Component life cycle
In this topic
Flex is an event-driven programming model. All Flex components undergo the same instantiation life cycle during which Flex automatically calls component methods, dispatches events, and makes the component visible.
Knowing the details of this life cycle will help you understand the sequence of events, which allows you to listen and wait for the proper events.
Instantiation life cycle
The following diagram shows the instantiation life cycle for both Flex and ArcGIS API for Flex. The various stages are described below.
After all components are created and drawn, the Application object dispatches an applicationComplete event. This is the last event dispatched during application startup.
- preinitialize—An event dispatched before initialization takes place. When Flex dispatches the preinitialize event, the children of a component, including internal children, have not yet been created. It is only useful in rare situations when you must set properties on a parent before the children are created.
- childAdd—Dispatched on the parent container after all children have been initialized but before the component has been sized and processed for layout.
- initialize—An event dispatched to alert initialization. At this time, all the component's children have been initialized, but the component has not been fully processed or sized for layout.
- creationComplete—Signals that the object is complete. This is called after Flex sets the visible property to true. The component has been sized and processed for layout and all properties are set. This event is dispatched only once.
- updateComplete—Flex dispatches additional updateComplete events whenever the position, size, or other visual characteristic of the component changes and the component has been updated for display.
- load—Specific to the ArcGIS API for Flex. This applies to Map and Layer and, consequently, GraphicsLayer, ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer, ArcGISImageServiceLayer, and ArcIMSMapServiceLayer events. It is dispatched after its properties are set up but before the map is downloaded and displayed.
When working with maps and layers, use the load event in the ArcGIS API for Flex instead of the generic creationComplete event. This will ensure that map properties, such as extent and spatialReference, are available.
For further information about the Flex life cycle, see the following: