Actionscript 3 Simple click EventListener

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 movieClip 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!")
    }

This entry was posted in AS3, Flex. Bookmark the permalink.

One Response to Actionscript 3 Simple click EventListener

  1. Almog Koren says:

    I did a post on Tip and Tricks for event listeners this might help everyone
    http://www.almogdesign.net/blog/actionscript-3-event-listeners-tips-tricks/

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>