2
votes

I have my custom component and for example few Label. I want to pass to my component value which will be assign to label's id.

Code:

<fx:Script>
        <![CDATA[
            [Inspectable]
            [Bindable]
            public var test:String = "asd";
        ]]>
</fx:Script>
<s:Label id="{test}" text="etc"/>

Error: {test} is not a valid identifier

Can I even do something like that?

1
Can I ask why? what's the point of doing that? - J_A_X

1 Answers

6
votes

No you can't. You have to understand that when you write an mxml component like

<s:Group>
    <s:Label id="myLabel" />
</s:Group>

it will generate ActionScript code like

public class MyClass extends Group {
    public var myLabel:Label;
}

(Mind you, I grossly oversimplify the code here to convey the most important part).

As you can see your 'id' is in fact a property name. And you can't change a property's name at runtime can you?