Flex – How to write MXML to attach a listener to a custom ActionScript class

For example, the following M XML script attaches a listener to the Button class:

I have a custom action script class that triggers an event when the value is updated and I want to be able to listen to the event in the MXML class :

ActionScript class:

public function set currentPage(newCurrentPage: Number): void {
_currentPage = newCurrentPage;
< br /> dispatchEvent(new DataEvent(PAGE_CHANGED, true, false, _currentPage));
}

I want to be able to perform the following operations in MXML:

 pageChanged="doMoreStuff()" />

What should I do? Cheers:)

You must declare events with metadata tags:

< p>


[Event(name="pageChanged", type="full.type.name.of.DataEvent")]

The event name must match the event name (PAGE_CHANGED constant in the example).

Edit: If you use ActionScript instead of MXML to write the class, you can mark the metadata directly Applied to your class:

[Event(name="pageChanged", type="full.type.name.of.DataEvent")]
public class MyClass extends WhateverItExtends

For example, the following M XML script attaches a listener to the Button class:

 

I have a custom action script class, when the value is updated and I want to be in the MXML class Trigger the event when listening to this event:

ActionScript class:

public function set currentPage(newCurrentPage: Number): void {
_currentPage = newCurrentPage;

dispatchEvent(new DataEvent(PAGE_CHANGED, true, false, _currentPage));
}

I want to be able to perform the following operations in MXML:

 pageChanged="doMoreStuff()" />

What should I do? Cheers:)

You must declare events with metadata tags:


[Event(name="pageChanged", type="full.type.name.of.DataEvent")]

The event name must Match the event name (PAGE_CHANGED constant in the example).

Edit: If you use ActionScript instead of MXML to write the class, you can apply metadata tags directly to your class:

[Event(name="pageChanged", type="full.type.name.of.DataEvent")]
public class MyClass extends WhateverItExtends

< p>

Leave a Comment

Your email address will not be published.