You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Harbs <ha...@gmail.com> on 2017/03/02 14:10:25 UTC

ArrayElementType?

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?

Re: ArrayElementType?

Posted by Carlos Rovira <ca...@codeoscopic.com>.
In my experience this metadata was almost useless since as Clint said is
only MXML,
but you should get remote data 99% of the times, so in the end you end not
using it
for the few cases that you could have declared in code (that should be
typical hello worlds
basic examples that doesn't match real world at all)

2017-03-02 17:49 GMT+01:00 Alex Harui <ah...@adobe.com>:

>
>
> On 3/2/17, 8:11 AM, "Harbs" <ha...@gmail.com> wrote:
>
> >Interesting.
> >
> >So this only works with MXML or with ActionScript too?
>
> Just MXML.  We could try to get the compiler to use it when checking
> assignments in ActionScript, but I think that there would be cases where
> it wouldn't do the right thing since AS allows some forms of automatic
> type conversion.  And still, that would only be compile-time.  The Flash
> runtime does not use Metadata to guide runtime behavior.  Vector was
> introduced to provide runtime support for typed arrays.
>
>
> >
> >I’m wondering if we can use this for typed arrays in externs compiled
> >using compc.
>
> ExternC will emit ArrayElementType for certain patterns, but not currently
> for the one you ran into.
>
> Thanks,
> -Alex
>
>


-- 

Carlos Rovira
Director General
M: +34 607 22 60 05
http://www.codeoscopic.com
http://www.avant2.es

Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si ha recibido este mensaje por
error, le rogamos que nos lo comunique inmediatamente por esta misma vía y
proceda a su destrucción.

De la vigente Ley Orgánica de Protección de Datos (15/1999), le comunicamos
que sus datos forman parte de un fichero cuyo responsable es CODEOSCOPIC
S.A. La finalidad de dicho tratamiento es facilitar la prestación del
servicio o información solicitados, teniendo usted derecho de acceso,
rectificación, cancelación y oposición de sus datos dirigiéndose a nuestras
oficinas c/ Paseo de la Habana 9-11, 28036, Madrid con la documentación
necesaria.

Re: ArrayElementType?

Posted by Alex Harui <ah...@adobe.com>.

On 3/2/17, 8:11 AM, "Harbs" <ha...@gmail.com> wrote:

>Interesting.
>
>So this only works with MXML or with ActionScript too?

Just MXML.  We could try to get the compiler to use it when checking
assignments in ActionScript, but I think that there would be cases where
it wouldn't do the right thing since AS allows some forms of automatic
type conversion.  And still, that would only be compile-time.  The Flash
runtime does not use Metadata to guide runtime behavior.  Vector was
introduced to provide runtime support for typed arrays.


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

ExternC will emit ArrayElementType for certain patterns, but not currently
for the one you ran into.

Thanks,
-Alex


Re: ArrayElementType?

Posted by Harbs <ha...@gmail.com>.
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 <cm...@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 <ha...@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?
>> 


Re: ArrayElementType?

Posted by Clint M <cm...@gmail.com>.
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 <ha...@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?
>