Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 201

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

Advertisement

In MXML, when the compiler encounters a value declaration for a property of type
IDeferredInstance, instead of generating code to construct and assign the value to the
property, the compiler generates code to construct and assign an IDeferredInstance
implementation object, which then produces the value at run time.
You can pass any data type to a property of type IDeferredInstance. In the example in the
section
"About template components" on page
195, you pass a Label control to the topRow
property, and three Button controls to the bottomRow property.
Notice in the example that the
methods that take topRow and bottomRow as
addChild()
arguments cast them to UIComponent. This cast is necessary because the
addChild()
method can only add an object that implements the IUIComponent interface to a container;
and the
method returns a value of type Object.
DeferredInstance.getInstance()
Defining properties using the IDeferredInstance
interface
This section describes how to define component properties of type IDeferredInstance.
Defining a generic property
To define a generic property, one with no associated data type, you define its type as
IDeferredInstance, as the following example shows:
// Define a deferred property for the top component.
public var topRow:IDeferredInstance;
The user of the component can then specify an object of any type to the property. It is your
responsibility in the component implementation to verify that the value passed by the user is
of the correct data type.
Restricting the data type of a property
You use the
metadata tag to specify the allowed data type of a property of
[InstanceType]
type IDeferredInstance, as the following example shows:
// Define a deferred property for the top component.
[InstanceType("mx.controls.Label")]
public var topRow:IDeferredInstance;
The Flex compiler validates that users only assign values of the specified type to the property.
In this example, if the component user sets the topRow property to a value of a type other
than mx.controls.Label, the compiler issues an error message.
Implementing a template component
201

Advertisement

Table of Contents
loading

Table of Contents