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.


Comments (6)              | 738 Views | Tags: Flex


Comments
Campbell's Gravatar Yep by default the Tabcontainer doesnt actually create the next tabs chilren (ie your component) untill that tab is selected. Which is why the id will be pointing to null.
# Posted By Campbell | 4/3/08 9:55 PM
Theo Rushin's Gravatar Hi,
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?
# Posted By Theo Rushin | 4/3/08 9:59 PM
Dusty's Gravatar Mike: I ran into this a long while ago with ViewStack, and I realized that creationPolicy is a very good thing, as creating all of those components can slow your application's first couple of frames, making things look like they are stuttering.

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"
# Posted By Dusty | 4/3/08 10:35 PM
Tony Fendall's Gravatar @Theo:
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.
# Posted By Tony Fendall | 4/3/08 11:48 PM
Mike Benner's Gravatar My gripe was more with the fact that (at least in my experience) it was difficult to find this information and that it seemed contrary to what I had seen so far with the other components I was using.

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.
# Posted By Mike Benner | 4/4/08 12:41 AM
Miyuki's Gravatar Mike: This was very helpful. Thank you so much.
# Posted By Miyuki | 7/18/08 10:35 AM