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>