Need Flex Migration Help?
- Adobe ends Flash player support in 2020
- Flex apps will no longer function
- We can help migrate your app
Did you know you are not limited to working with the events built into components, but you can broadcast your own events as you need to within Flash and Flex? Its actually really easy, and gives great ability to loosely couple the application.
If you are working in a subclass of UIObject (in Flex, virtually everything fits into this category), the methods of the EventListener class are already available, so you can simply say:
this.dispatchEvent(someEventObject);
Where someEventObject is an instance of an object containing a property called type. The event objects target property is automatically added when the event is dispatched. If you need to, you can add other properties to the event, notifying the application of what happened, and giving it appropriate data to react.
If you are looking to do this in Flash from a standard movieClip, instead of a subclass of UIObject, you’ll need to manually initialize the EventDispatcher. Something like this:
mx.events.EventDispatcher.initialize(this);
This will add the methods addEventListener(), removeEventListener() and dispatchEvent() to the movieClip which was passed to the initialize method.
You can download an example of this here