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