Mike Benner
Hmmm, need something catchy for here...
Flex Quirk
Apr 3 by Michael Benner
So the flex development has been going well and I am learning great deals of what has changed (and what hasn't) since my last foray into this realm. There, however, is one thing that just had me banging my head against the proverbial wall without a helmet. The TabNavigator and
a little known attribute called "creationPolicy".
Every time I tried to reference a component in a container within the TabNavigator it would return a "null reference" error. Now I know it is there, the "id" is correct and no matter what I did in ActionScript it was unavailable. I finally was able to determine it was only when I was using the TabNavigator which helped narrow it down.
After scouring the Internet for hours (yes, really hours) I found a comment at the bottom of this page.
Yes, that one. The one that says you MUST set the creationPolicy="all". So, I did and everything works. But here is my gripe. Everything I read prior to this said that "id" was all you needed and it was true for everything but this control. Why is that attribute NOT defined by default to "ALL".
Anyway, for all those that share this frustration, there is your solution hopefully this post will make it easier for others to find in the future.
The creationPolicy attribute helps to increase the perceived speed of your application. An app that features a TabNavigator component containing a vast amount of children components would take more time to load. Children components would be instantiated and loaded into memory even if they are never needed. Having creationPolicy set to none by default is a good thing.
Curious … why would you need to directly access a hidden child component?
I found that I didn't need to set the policy to "All", I needed to stick to the MVC Architecture and not take shortcuts... once I coded everything properly, things worked perfectly *and* made more sense... take a look at your code and see if you can change the way you are doing things, so you don't need to set the policy to "all"
There are many cases where one wants to initialize many pages (tabs) of a configuration dialog with initial values when the dialog is opened. Cases like there are where the creation policy is most commonly encountered.
In the bigger picture, I do see the point of not loading "all" by default (my pod was small and would not be affected by that), so I take back the load all.