I could not get the event to dispatch. is there any thing missing in my code?
Application1.mxml:
<s:Button x="50" y="10" label="But开发者_StackOverflow中文版ton" click="dispatchEvent(new Event('buttonToggle'))"/>
component1.mxml
[Bindable(event="buttonToggle")]
public function disableChk():void {
trace("event");
}
It is not very clear what do you want to ask but I'll try to explain the code I see.
First, dispatching and listening events are performing by dispatchEvent()
and addEventListener()
of flash.events.EventDispatcher
. So you're dispatching event right. But what about listening? To listen to event you should add something like (in the same MXML class where event is dispatching):
addEventListener("buttonToggle", onButtonToggle);
…
private function onButtonToggle(event:Event):void
{
trace("event");
}
What about your example it is not about event handling but about data binding. And of course data binding relies on event dispatching/handling under the hood but there are some limitations to check if event dispatching works using data binding.
First of all, you're using function as a source of data binding. And there are to problems with it:
- Using bindable function without returning value (you have
void
) is non-sense. - Even if your function will return value it won't call if there is no any bindings in MXML attributes to this function.
But to solve problem of your code (but not your question) we need to have more information about your goal and more code about your implementation.
For the simplest way of handling events of MXML components within the same component you can use very simple handlers:
<s:Button x="50" y="10" label="Button" click="myClickHandler()"/>
and:
private function myClickHandler():void
{
trace("Event");
}
You can read more about handling events from the official documentation.
精彩评论