Macromedia flex 2 Manual

Page of 254
50
Using Metadata Tags in Custom Components
The following sections describe the component metadata tags in more detail.
ArrayElementType metadata tag
When you define an Array variable in ActionScript, you specify 
Array
 as the data type of the 
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]
 metadata tag to specify the allowed data type of the Array 
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]
 metadata tag before the variable definition. The tag has 
the following syntax: 
[ArrayElementType("elementType")]