200
Creating Template Components
The following example shows an alternative implementation for the MyTemplateComponent
component shown in the section
“About template components” on page 195
, named
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,
getInstance()
. Flex calls the
getInstance()
method to initialize a property when it creates an instance of the component.
A subsequent call to the
getInstance()
method returns a reference to the property value.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...