Return to Kroll Web Design home page Flash tutorials

« Return

ActionScript 3

Event Listener

An event listener does just that — it listens for events such as mouse clicks, keyboard presses, or whatever type of event is specified. When the event is detected by the event listener, it calls the specified function.

Download the FLA file

Add an event listener to the Start button and the Stop button, such that if the Start button is clicked, the startAnim function will be called, and such that if the Stop button is clicked, the stopAnim function will be called.

start_btn.addEventListener(MouseEvent.CLICK, startAnim);
stop_btn.addEventListener(MouseEvent.CLICK, stopAnim);

ball_animation_mc.stop();

function startAnim(e:MouseEvent):void 
{
	ball_animation_mc.play();
}

function stopAnim(e:MouseEvent):void 
{
	ball_animation_mc.stop();
}