For example, the following MXML script attaches a listener to a Button class:
<mx:Button id="STACK" label="OVERFLOW" click="doStuff()"/>
I have a custom action script class which fires an event when a value is updated and I wish to be able to listen for that event in an MXML class:
ActionScript Class:
public function set currentPage(newCurrentPage: Number) : void {
_currentPage = newCurrentPage;
dispatchEvent(new DataEvent(PAGE_CHANGED, true, false, _currentPage));
}
And I wish to be able to do the following in MXML:
<myClass:Class <...> pageChanged="doMoreStuff()" />
How would I do this? Cheers :)
You have to declare the event with a metadata tag:
<mx:Metadata>
[Event(name="pageChanged", type="full.type.name.of.DataEvent")]
</mx:Metadata>
The name of the event must match the event name (PAGE_CHANGED constant in your example).
Edit: if you're writing the class in ActionScript instead of MXML, you can apply the metadata tag directly to your class:
[Event(name="pageChanged", type="full.type.name.of.DataEvent")]
public class MyClass extends WhateverItExtends
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With