Understanding State Life Cycles

One aspect of states that initially can be confusing is the life cycle of the components within a state. As you learned in Managing Object Creation Policies (Preloading Objects)” earlier in this chapter, by using states you can manage the creation policy for components within the state. By default, all the components in a state are not created until the state is first requested. You also learned that you can control the creation policy such that components are created when the application starts up regardless of whether they belong to the base state, or you can manually create the components in a state. That covers the possibilities for how and when components in states can get created. Next, we need to look at what happens to components once they have been created, because this point can cause a fair amount of confusion if misunderstood.

When a state is set to the current state one of two possible things can happen. If the components in the state have already been created they are immediately added to the display list; if the components haven’t yet been created they are first created and then added to the display list. On the other end of things, when a state is replaced as the current state only one thing can happen: the components that are part of that state are removed from the display list. Once the components in a state have been created, they are not destroyed. Replacing a state as the current state does not destroy the components it contains. ...

Get Programming Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.