简体   繁体   English

在flex4&as3中,如何动态更改按钮标签?

[英]In flex4 & as3 how do you change the button label dynamically?

Is there any way to change Spark button label dynamically? 有没有办法动态更改Spark按钮标签? When i click on it, i want the label to change. 当我点击它,我希望标签改变。 I bind the String to label and gives value for the first time, but even flashBuilder shows me that Data binding will not be able to detect assignments. 我将String绑定到label并首次给出值,但即使flashBuilder也向我显示Data绑定将无法检测赋值。 Here is my button: 这是我的按钮:

<s:Button name="button" label="{butt}" x="5" y="3" useHandCursor="true" 
          click="start()" buttonMode="true" cornerRadius="5" 
          skinClass="skins.CustomButtom"/>

And here is assigment: 这是分配:

public var butt:String = "Start";

Update Both answers work. 更新两个答案都有效。

Make the variable Bindable like this: 使变量Bindable像这样:

[Bindable]  
public var butt:String = "Start";

It is not advisable to have buttons with changing labels. 不建议使用带有更换标签的按钮。
Even if you must, it is preferable to change the label property directly instead of introducing a binding because Flash Player needs to instantiate extra listeners for bound variables. 即使必须,也最好直接更改label属性而不是引入绑定,因为Flash Player需要为绑定变量实例化额外的侦听器。
In this case, a binding is required only if you are going to be changing the label frequently. 在这种情况下,只有在您要经常更改标签时才需要绑定。

Without the bindable, you might have noticed that Flash will assign the value "Start" to the label of the button (generally, the value of the bound variable at the time of creation of the button). 如果没有可绑定,您可能已经注意到Flash会将值"Start"分配给按钮的标签(通常是创建按钮时绑定变量的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM