Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 200

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

The following example shows an alternative implementation for the MyTemplateComponent
component shown in the section
MyTemplateComponentDeferred.mxml, by defining the topRow and bottomRow properties
to be of type IDeferredInstance:
<?xml version="1.0"?>
<!-- templating/myComponents/MyTemplateComponentDeferred.mxml -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.containers.HBox;
import mx.core.UIComponent;
// Define a deferred property for the top component.
public var topRow:IDeferredInstance;
// Define an Array of deferred properties
// for a row of components.
[ArrayElementType("mx.core.IDeferredInstance")]
public var bottomRow:Array;
private function init():void {
// Add the top component to the VBox container.
// Cast the IDeferredInstance object to UIComponent
// so that you can add it to the parent container.
addChild(UIComponent(topRow.getInstance()));
// Create an HBox container. This container
// is the parent container of the bottom row of components.
var controlHBox:HBox = new HBox();
// Add the bottom row of components
// to the HBox container.
for (var i:int = 0; i < bottomRow.length; i++)
controlHBox.addChild(UIComponent(bottomRow[i].getInstance()));
// Add the HBox container to the VBox container.
addChild(controlHBox);
}
]]>
</mx:Script>
</mx:VBox>
The IDeferredInstance interface defines a single method,
method to initialize a property when it creates an instance of the component.
getInstance()
A subsequent call to the
200
Creating Template Components
"About template components" on page
method returns a reference to the property value.
getInstance()
195, named
. Flex calls the
getInstance()

Advertisement

Table of Contents
loading

Table of Contents