我有一些带按钮的VBox。我希望我的按钮在点击后更改标签。我正在尝试使用代码隐藏实践,但按钮的实例始终为null。有代码:
package TestPackage
{
import mx.containers.VBox;
import mx.controls.Button;
public class ControlsBox extends VBox
{
[Bindable]
public var btnPlay : Button;
public function ControlsBox()
{
super();
}
override protected function childrenCreated():void
{
super.childrenCreated();
}
public function ChangeImage():void
{
btnPlay.label = "a";
}
}
}
Here is mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="TestPackage.*">
<controls:ControlsBox id="ctrlVBox">
<mx:Button id="btnPlay" click="this.ctrlVBox.ChangeImage();" label="c"></mx:Button>
</controls:ControlsBox>
</mx:Application>
我做错了什么?以及如何正确地做到这一点? 感谢
答案 0 :(得分:0)
我不会经常在flex中这样做,但我认为你想要这样的东西:
<controls:ControlsBox id="ctrlVBox">
<controls:btnPlay>
<mx:Button click="this.ctrlVBox.ChangeImage();" label="c"></mx:Button>
</controls:btnPlay>
</controls:ControlsBox>