将变量分配给 MXML 组件 ID

发布于 2024-11-17 15:38:58 字数 341 浏览 3 评论 0原文

我有我的自定义组件和例如几个标签。我想传递给我的组件值,该值将分配给标签的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲爱恨情仇 2024-11-24 15:38:58

不,你不能。您必须明白,当您编写这样的 mxml 组件时

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

,它将生成类似的 ActionScript 代码

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

(请注意,我在这里严重简化了代码以传达最重要的部分)。

正如您所看到的,您的“id”实际上是一个属性名称。而且您不能在运行时更改属性的名称,对吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文