Dispatching an event

Buttons are binded with event listeners. When you click, for example, a button, the event listener that you have defined is called and an a desired action is taking place. But what if you want to perform the listener without interacting with the button? Let's say that we want to click the button, but not by actually clicking it, but by calling the click from another function. To do so:

var myButton:MovieClip = new MovieClip();  
myButton.addEventListener( MouseEvent.CLICK, myClickFunction, false, 0, true);

// run this when desired
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));  

Check out this great tutorial from ActiveTuts for more.

Post A Comment

Anti-Spam Quiz: