开发者

Assign variable to MXML component ID

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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜