Friday, September 2, 2011

Flex :: Metadata tag - Array Element Type

In ActionScript language whenever we define an Array variable, we never specify data type of elements that Array will hold.

To allow Flex compiler to perform type checking on Array elements, we can use [ArrayElementType] metadata tag. This metadata tag allow us to specify data type of Array element.

The tag has following syntax:

[ArrayElementType("elementType")]

The property elementType of [ArrayElementType] metadata tag specifies the data type of Array elements, and can be one of the ActionScript data types, such as String, Number, uint, class or interface.

Incase of user defined class, fully qualified class name, including package detail is expected.

For Example:

....

<fx:Script>
<[!CDATA[
   [ArrayElementType("String"]
   public var strProp:Array;

   [ArrayElementType("myPackage.valueObject.data"]
   public var dataProp:Array;
...
]]>
</fx:Script>

....

Note: The MXML complier checks for proper usage of the Array elements only in MXML code; it does not checks Array usage in ActionScript code.

No comments:

Post a Comment