Monday, August 29, 2011

UIComponent.stage

An important class of note in Flex applications is the Stage. Every DisplayObject has a reference to the stage class and it is worth noting that the Flash runtime has only one Stage object. What the stage does is it acts as a container for all the display objects. Any display objects that we can see on the screen will have a reference to the stage of the run time and all of them will refer to the same object.
It is also important to note when the stage for a particular object is set. Before initialization the stage is null for every object. During the initialization of a component Flex fires an event called "ADDED_TO_STAGE". This is when the object is added to the main stage. If one needs to use the stage for anything, it is advisable to listen to this event so as to avoid null pointer exceptions.
A simple usage of the stage is to set the application to fill the screen,
       uiComponent.stage.displayState = StageDisplayState.FULL_SCREEN;
Other usage of the stage may be for resize operations or to fire a common event for all the Objects on display.

No comments :