Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 50

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

Advertisement

The following sections describe the component metadata tags in more detail.
ArrayElementType metadata tag
When you define an Array variable in ActionScript, you specify
variable. However, you cannot specify the data type of the elements of the Array.
To allow the Flex MXML compiler to perform type checking on Array elements, you can use
the
[ArrayElementType]
elements, as the following example shows:
public class MyTypedArrayComponent extends VBox {
[ArrayElementType("String")]
public var newStringProperty:Array;
[ArrayElementType("Number")]
public var newNumberProperty:Array;
...
}
In this example, you specify String as the allowed data type of the Array elements. If a user
attempts to assign elements of a data type other than String to the Array in an MXML file, the
compiler issues a syntax error, as the following example shows:
<MyComp:MyTypedArrayComponent>
<MyComp:newStringProperty>
<mx:Number>94062</mx:Number>
<mx:Number>14850</mx:Number>
<mx:Number>53402</mx:Number>
</MyComp:newStringProperty>
</MyComp:MyTypedArrayComponent>
In this example, you try to use Number objects to initialize the Array, so the compiler issues
an error.
You can also specify Array properties as tag attributes, rather than using child tags, as the
following example shows.
<MyComp:MyTypedArrayComponent newNumberProperty="[abc,def]"/>
This MXML code generates an error because Flex cannot convert the Strings {abc} and {def }
to a Number.
You insert the
[ArrayElementType]
the following syntax:
[ArrayElementType("elementType")]
50
Using Metadata Tags in Custom Components
metadata tag to specify the allowed data type of the Array
metadata tag before the variable definition. The tag has
as the data type of the
Array

Advertisement

Table of Contents
loading

Table of Contents