The example below demonstrates the working of flex dispatchEvent() method.
Method works like a driver that drives the event mentioned in its constructor.
This method is used to manually dispatch or run away an event. Method, to
dispatch any event on the component can be applied either with the
component's id or mouseOver
attribute. With mouseOver attribute the method will be used inside the mxml tags.
This means with and inside a control tag attribute, mouseOver the
method can be dispatched on any component.
Note: With id attribute, method can be accessed through inside as well as outside the mxml tags.
Note: mxml tags are the tags used inside the flex application root tag. eg. Flex component tags like control and container tags.
Syntax for using the method
component's id.dispatchEvent(event_ type, boolean value, boolean
Example for event_type used in the method constructor is MouseEvent.CLICK.
eg:-- b1.dispatchEvent(MouseEvent.CLICK, false ,true);
Inside the method constructor, the first
parameter is the event type specified that will be run or dispatch away by the dispatchEvent
the second and third parameter are optional parameters that accept boolean
values true and false.
Now in the example below, when the mouse arrow is passed over the component in which the dispatchEvent method is invoked,
method dispatches the MouseEvent.CLICK type event on the component.
With this method, the click based events on components like buttons, check boxes etc can be manually set to run before the MouseEvent.CLICK i.e. mouse click, actually takes place.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial