flamingsquirrel

Archive for the ‘AS3’ Category

Actionscript 3 Simple click EventListener

Monday, February 23rd, 2009

If like me you are making the transition from Actionscript 2 to 3 you may well find that creating simple onPress functions don’t use the same syntax. I checked the Adobe help files but got confused by the overly complex details.

If you want a simple clickable moveClip use the following code. The first line means that the movie clip will act like a button and the cursor will change when the mouse is hovering over.

movieclip_name.buttonMode = true;
movieclip_name.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void{
trace(“Yes, this works!”)
}

Subscribe to this site