views:

4860

answers:

4

I seem to be running into an issue (Cannot access a property or method of a null object reference) binding events in actionscript to a viewstack layer not currently showing. Are those objects not created until that layer is visible for the first time? I remember something about a creation policy, if this is the case, can I force it to create those children before that layer is viewed?

+2  A: 

Yeah, I had this same problem myself while working on an application with a PureMVC structure. I was unable to create mediators for the subcomponents of a ViewStack because they were constructed lazily by the Flex framework.

Here's where I eventually found my solution:

http://forums.puremvc.org/index.php?topic=280.0

benjismith
A: 

Found the relevant documentation here. Seems like that'd be something you'd make a note of on the container docs.

mjard
+8  A: 

Yes, that's right -- ViewStack children are created only when needed by default ("deferred instantiation" is a phrase you'll hear thrown around in this context). If instead you want to instruct Flex to create all of the ViewStack container's children up front, consider using the creationPolicy property common to all mx.core.Containers:

A creationPolicy of ContainerCreationPolicy.ALL means that the navigator containers immediately create deeper descendants for each child, rather than waiting until that child is selected.

<mx:ViewStack id="myStack" creationPolicy="all" />

It's a bit slower on startup, because you're creating a bunch of child components you might not need yet, but as long as you keep that tradeoff in mind, it may come in handy sometime.

Christian Nunciato
A: 

THANKHS YOU save me much time

mungu