This post is part of a series of articles in which I will try to explain in detail how events work in Flex, how you can handle Flex events, how you can create your custom Flex events and more.
In the previous article I talked about Flex custom events. We created a new custom event:
var eventToBeDispatched:Event = new Event('yourCustomEvent'); |
Then we dispatched the event to the parent component.
dispatchEvent(eventToBeDispatched); |
The event was registered to the Flex Framework between metadata tags:
<fx:metadata> [Event(name="yourCustomEvent", type="flash.events.Event")] </fx:metadata> |
So we used mxml register the event handler to the custom event:
<components:lowerhalf yourCustomEvent="lowerhalf1_yourCustomEventHandler(event)"></components:lowerhalf> |
The handler function lowerhalf1_yourCustomEventHandler(event) just displayed a random number a label.
Although this approach allows for using a custom event type it has a major drawback: we can’t pass any custom data along with the event object. This is due to the fact that the flash.events.Event class doesn’t support additional properties.
Read the rest of this entry »