components, , , " />

FlashPlatformist
Articles, Information, News, & Tutorials for Adobe Flash Platform Developers and Architects

Life Cycle of the Flex UIComponent Base Class

The Flex documentation on the UIComponent life cycle is rather difficult to understand, and so I came up with what I felt was an easier and more logical way of describing the process. I felt this might be useful for those who are interested in creating custom visual components in Flex that extend the UIComponent class. Creating custom components without having a solid understanding of the functionality that is abstracted within the Flex framework in regard to how it lays out UIComponent objects will likely result in design decisions that are inconsistent with the Flex Framework, which could potentially lead to a frustraing and seemingly uphill battle between the developer and the framework.

The following flow diagram represents the process that is abstracted within the Flex framework when the addChild() command is made to create and make a visual component visible on the stage, or when the properties of the component and/or it’s parent change (like a new data update for example):

Life Cycle of a Flex UIComponent

Life Cycle of a Flex UIComponent

Note that if that is a little hard to read, you can click on it and it will brink up a pdf version. This is identical to what is said in the Flex documentation, it is just a lot easier to understand for those of us who appreciate visual representations of processes that are comprised of many steps. It is just easier to follow.

You will notice toward the bottom the diamond shape, which represents a decision that has to be made. The thing to understand here, is that additional components may be going through this same process simultaneously, thus affecting the layout properties of each other. An example might be the resizing of the parent window. The invalidation methods in essence, act as a sort of “queue” so to speak, so the actual stage ends up redrawing just once even though a number of things may have changed. The point at which the UIComponent makes the decision on whether or not to re-render is sort of like it is checking itself to make sure that it is ready before becoming visible. If a number of visual properties have been set on it or something else changed again that forced the invalidation methods to be called again on the components, it re-runs the commitProperties(), measure(), layoutChrome(), and updateDisplayList() methods again, and will continue to do so until it knows that it is now ready to be seen, at which point it’s visible property is set to true.

The speed at which this all happens and the overall architectural decisions with regard to how the stage is drawn in a Flex app and the way the visual elements are laid out, is truly quite impressive, and worth studying in further detail if you are interested in learning more about the design patterns used in the Flex framework to make it work the way it does. Although Flex does have its flaws, this is an example of how the framework abstracts a lot of functionality quite elegantly for the developer.

Possibly Related Posts:



Posted by Dan Orlando on February 7th, 2009 :: Filed under Tutorials
Tags :: , , ,
You can leave a response, or trackback from your own site.

10 Responses to “Life Cycle of the Flex UIComponent Base Class”

  1. flashmattic
    June 28th, 2009

    At last, some flow chart that is easy to follow each time you need to dive into the component’s life cycle.
    Cheers mate!

  2. [...] with Flex 3, then I certainly hope you are familiar with the UIComponent class. If not, I suggest reading up on it before going any further with any Flex [...]

  3. Gavin
    September 24th, 2009

    This is awesome, really nice and easy to understand…book marking this one for sure

  4. Lorenzo
    October 25th, 2009

    Very good post!

    Can I ask you some questions?

    How does this model fit into frame by frame mentality?

    Are there any differences (or analogies) between frames understood as the unit that contains actionscript code (like in a Creative Suite) and frames understood as the time slot between two consecutive enterframe events?

    Thanks in advance.
    Best regards,
    Lorenzo

  5. Ravi
    November 10th, 2009

    can you explain the flow of the component life cycle briefly.

    Thanks,
    Ravi

  6. Arizona
    December 3rd, 2009

    I appreciate the flowchart. Might I suggest an additional node get added to the end that indicates that “addedToStage” event is dispatched.

    I see this as an important event to know about since most references suggest removing event listeners during the “removedFromState” event.

    Thanks again,
    -Arizona

  7. Arizona
    December 3rd, 2009

    Well, upon further investigation, I’ve found that there are instances where the “addedToStage” event can occur BEFORE the “creationComplete” event.

  8. Mayur
    December 8th, 2009

    I think that this is the most helpful flowchart. Easy to understand and covers all the basic concepts right-away..

  9. AS Workflow - Flashforum
    July 12th, 2010

    [...] Danorlando hat mal den LifeCycle in einem Diagramm verpackt. Vielleicht hilft es dir ja auch weiter. Life Cycle of the Flex UIComponent Base Class – FlashPlatformist [...]

  10. Ashine
    August 4th, 2010

    Dear Dan,

    As per my understanding, childAdd on parent container precedes ‘Preinitialize’ Event on the child component,
    And the order is as follows: (ChildContainer is a container inside Appliocation)

    PREINITILIAZE (Application)
    CREATECHILDREN (Application)
    CONSTRUCTOR (ChildContainer)
    CHILDADD (Application)
    PREINITIALIZE (ChildContainer)
    CREATECHILDREN (ChildContainer)
    CHILDADD (ChildContainer)
    Initialize (ChildContainer)
    Initialize (Application)

    And like wise ………………….

    You may also refer to “http://livedocs.adobe.com/flex/3/html/help.html?content=components_06.html” where this is clearly mentioned :

    “Flex dispatches the childAdd event from the parent container.
    Flex dispatches the preinitialize event on the component. The component is in a very raw state when this event is dispatched. Many components, such as the Button control, create internal child components to implement functionality; for example, the Button control creates an internal UITextField component to represent its label text. When Flex dispatches the preinitialize event, the children (including the internal children, of a component) have not yet been created.

Leave a Reply

Type your comment in the box below: