指定变量MXML组件ID [英] Assign variable to MXML component ID

查看:150
本文介绍了指定变量MXML组件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的自定义组件,例如一些标签。我想通过我将被分配到标签的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>

它会生成ActionScript code像

it will generate ActionScript code like

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

(请注意,我非常过分简化了code在这里要传达的最重要的部分)。

(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?

这篇关于指定变量MXML组件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆