将变量分配给 MXML 组件 ID
我有我的自定义组件和例如几个标签。我想传递给我的组件值,该值将分配给标签的 id。
代码:
<fx:Script>
<![CDATA[
[Inspectable]
[Bindable]
public var test:String = "asd";
]]>
</fx:Script>
<s:Label id="{test}" text="etc"/>
错误:{test} 不是有效的标识符
我什至可以做类似的事情吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能。您必须明白,当您编写这样的 mxml 组件时
,它将生成类似的 ActionScript 代码
(请注意,我在这里严重简化了代码以传达最重要的部分)。
正如您所看到的,您的“id”实际上是一个属性名称。而且您不能在运行时更改属性的名称,对吗?
No you can't. You have to understand that when you write an mxml component like
it will generate ActionScript code like
(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?