flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harbs <harbs.li...@gmail.com>
Subject Re: ArrayElementType?
Date Thu, 02 Mar 2017 16:11:02 GMT
Interesting.

So this only works with MXML or with ActionScript too?

I’m wondering if we can use this for typed arrays in externs compiled using compc.

I ran into that problem recently.

> On Mar 2, 2017, at 5:14 PM, Clint M <cmodien@gmail.com> wrote:
> 
> It's in the docs:
> http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html#WS2db454920e96a9e51e63e3d11c0bf69084-7a2c
> 
> 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;
>    ...
> }
> Note: The MXML compiler checks for proper usage of the Array only in MXML
> code; it does not check Array usage in ActionScript code.
> 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>
>        <fx:Number>94062</fx:Number>
>        <fx:Number>14850</fx:Number>
>        <fx:Number>53402</fx: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")]
> The following table describes the property of the [ArrayElementType]
> metadata tag:
> 
> Property
> 
> Type
> 
> Description
> 
> elementType
> String
> 
> Specifies the data type of the Array elements, and can be one of the
> ActionScript data types, such as String, Number, class, or interface.
> 
> You must specify the type as a fully qualified class name, including the
> package.
> 
> On Thu, Mar 2, 2017 at 6:10 AM, Harbs <harbs.lists@gmail.com> wrote:
> 
>> I just noticed a few places in TLF where we have such metadata. For
>> example:
>> 
>>                [ ArrayElementType("text.elements.TextFlowLine") ]
>>                private var _lines:Array;
>> 
>> Does anyone know what that does?
>> 


Mime
View raw message