Monday, July 28, 2008

addChild Component Instantiation In Table Form

In reading through the documentation on creating an advanced ActionScript component, I realized that it would be easier for me to understand if I had a more visual presentation of what happens when the addChild() method is called. So I have turned the "About the component instantiation lifecycle," section of "Creating and Extending Adobe Flex 3 Components" document (p. 134 of the PDF), into the table below.

Within the table, time goes from top to bottom. Also I have use the following color coding to try to make things a little clearer:

  • Dispatch Event

  • Invalidation Method used to tell Flex framework to call a Render Method

  • Render Method called by Flex Framework, not by components. These are the methods normally overriden when creating a custom ActionScript component, especially one that extends UIComponent.


StatusFlexContainerComponent
ActionScript: myContainer.addChild(myComponent);
parent = myContainer
style = {computed by Flex}
dispatch preinitialize event
createChildren()
invalidateProperties()
invalidateSize()
invalidateDisplayList()
all of the component's children have been initialized, but it has not been sized or processed for layout.
dispatch initialize event
dispatch childAdd event
dispatch initialize event
Start next render event
commitProperties()
measure() unless the user set component.height and component.width
layoutChrome() if component is a Container
updateDisplayList()
dispatch updateComplete event
dispatch additional render events if render methods called invalidation methods
last render event finishes
component is sized and processed for layout
visible = true
dispatch creationComplete event
dispatch updateComplete event

Note that the updateComplete event is dispatched whenever the layout, position, size, or other visual characteristic of the component changes and the component is updated for display. Thus it may fire a lot. For example, it will fire at least twice as part of adding a child component to a container.

No comments: