Significance of Vector and [ArrayElementType] type metadata

Posted: August 30, 2011 in Thoughts

We already know that ActionScript3 and FlashPlayer10 have a Vectors class for typed arrays. This Vector class is just an array in which all of its members have the same type and in addition to ensuring the collection is type safe, this can also provide performance improvements over using an Array. Apart from this Adobe Flex framework also introduced a metadata tag for typed array, called [ArrayElementType]. So for end-user developer can use any of these for typed array creation. Here I am penning my observation on this based on my experience. Before moving further I want to give you the official definition of these two terms.

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.

Adobe Live doc –

Vector Class

The Vector class lets you access and manipulate a vector, an array whose elements all have the same data type. The data type of a Vector’s elements is known as the Vector’s base type. The base type can be any class, including built in classes and custom classes. The base type is specified when declaring a Vector variable as well as when creating an instance by calling the class constructor. With an Array, you can use the array access operator ([]) to set or retrieve the value of a Vector element.

Adobe Live Doc –


By definition both are available for typed array creation. As per adobe documentation [ArrayElementType] metadata tag works properly in MXML code, so here I am going to give you the comparative example in both MXML and AS3 code for detail analysis.

ActionScript3 Codebase:


In the above example you can see that the [ArrayElementType] metadata tag is not working as it should be. As this is stated in adobe documentation that, the MXML compiler checks for proper usage of the Array only in MXML code; it does not check Array usage in ActionScript code. So we are moving into the MXML implementation. In the above example you will not get any compile time error only the runtime output is diverse.

MXML Codebase:
In this example I have created on custom template component in AS3 codebase and implemented that in MXML code. For more info on template component please check adobe documentation.

Code: This is a custom template component code.


In the above example you can see that the component implementation in MXML is throwing error as expected. But in these scenarios there are no specific deference in Vector and ArrayElementType.

On the basis of above example using Vector class we can achieve the entire typed array based requirement. We have already tested and found that Vector is more performance oriented then Array. So we don’t have any specific reason to use [ArrayElementType] metadata. Instead of using [ArrayElementType] we should use Vector class for better performance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s