1
我正在Flash Builder 4.5中构建MXML项目将更改事件添加到自定义MXML组件
我有一个包含TextInput字段的自定义MXML组件。我希望自定义组件具有触发主应用程序中某个功能的更改事件。
我已经搜索了这个网站,发现很多贴近我想要的帖子,但是我一直无法找到我需要的东西,现在我很困惑。
我创建了一个测试项目来尝试解决这个问题。目前,它似乎会触发一次事件,然后停止。请看一下,让我知道我哪里出错了。非常感谢。
customComponent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="40" height="20">
<mx:Script>
<![CDATA[
[Bindable]
public var value:Number;
protected function inputBox_clickHandler(event:KeyboardEvent):void
{
if (event.keyCode == 38) {
keyUp();
}
if (event.keyCode == 40) {
keyDown();
}
}
protected function keyUp():void
{
value = value++;
dispatchEvent(new Event('change'))
}
protected function keyDown():void
{
value = value--;
dispatchEvent(new Event('change'))
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name="change", type="flash.events.Event")]
</mx:Metadata>
<mx:TextInput id="inputBox" x="0" y="0" width="40" height="20"
text="{value}"
keyDown="inputBox_clickHandler(event)"
change="dispatchEvent(new Event('change'))"
/>
</mx:Canvas>
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:CustomComponents="CustomComponents.*"
minWidth="955" minHeight="600" layout="absolute">
<mx:Script>
<![CDATA[
private function changeTestLabel():void
{
testLabel.text = String(myComponent.value);
}
]]>
</mx:Script>
<CustomComponents:customComponent x="180" y="183"
id="myComponent" value="0"
change="changeTestLabel()">
</CustomComponents:customComponent>
<mx:Label id="testLabel" x="165" y="206" text="Test label"/>
</mx:Application>