topleft
topright
Slacker - A PureMVC/Flex Deferred Instantiation Demo Print E-mail
Monday, 18 August 2008

Image The simplest startup scenario for a PureMVC-based Flex or AIR app is that the MXML application creates itself first, then the PureMVC appraratus attaches itself to the app by registering Mediators for the already-constructed view components.

 

But Flex has a powerful feature called deferred instantiation of view components. It can help your application's startup performance, but it can complicate your code a bit as well. Understanding the default behavior with regard to this feature is essential to any Flex developer, regardless of whether you are using PureMVC.

 

In a ViewStack, for instance, although several children may be defined in the MXML, only the first visible child will be instantiated by default (creationPolicy="auto"). The other children will be instantiated only when you navigate to them. This is nice because it helps startup go faster, and the user may not navigate to all the children, so time and memory is conserved.

 

Unfortunately, now our simple scenario above is no longer enough, because at startup time, we don't have references to all the view components that will eventually need mediation - they haven't been created yet!. Although we could register the mediators and later give them references to the view components as they are created, that sort of defeats the point of deferred instantiation. So we need to defer the creation and registration of the Mediator as well.

 

View the demo and read the Release Notes for Slacker, and you'll get a much better idea how to use Flex's deferred instantiation to enhance your application's perceived responsiveness and conserve memory.

 




One thing to note here: Deferred instantiation is great, but OPTIONAL.


If the children of the ViewStack or TabNavigator are few and simple, then instead of jumping through hoops trying to deal with deferred instantiation in the framework, be a slacker and  simply set creationPolicy=all in your ViewStack and be done with it. All the children will be available when on creationComplete and you can just attach your Mediators.

 

This advice is only for the simplest cases!!! Deferred instantiation is the default behavior because it is expected that you want the most optimal startup experience. And if you have a ViewStack with many children it may take a long time to instantiate them, leading to a slower perceived response time. And since the user may never navigate to these children, it is wasteful of memory as well.

 

Delicious
Technorati
Reddit
Furl it!
NewsVine
YahooMyWeb
Stumble
blogmarks
Digg
co.mments
connotea
Last Updated ( Monday, 18 August 2008 )
 

Who's Online

We have 8 guests online

Join the Community!

PureMVC Developer Group

Supporters

Syndicate

PureMVC News
Copyright © 2006-2008 Futurescale, Inc.