Where's onRelease in AS 3?

It looks like AS 3 has done away with onRelease, onRollover etc. All of these still work in AS 2. But what do you do if you want to make a project in AS 3?

The following is the new system. Imagine you have made a Movie Clip button and named the instance on the stage b_0:

b_0.addEventListener( MouseEvent.CLICK, button_function );
b_0.buttonMode = true;
function button_function( evt:MouseEvent ) {
trace( "you clicked the button" );
}

If you are using a button clip you do not need the line:

b_0.buttonMode = true;

This is used to make MovieClip buttons show the hand cursor and automatically jump to the frame markers _up, _over and _down on their timeline.

If your button contains a text field, this can capture the mouse focus. That is rolling over the text within the button will take focus from the button as if you had rolled off it. Use the mouseChildren property to trap mouse events, keeping them from being passed on to nested objects.

b_0.mouseChildren = false;

For more infromation: http://www.communitymx.com/blog/index.cfm?newsid=863

4 thoughts on “Where's onRelease in AS 3?”

    1. Actually the new system is completely different. In the old system, onRelease was set to a function. You could only have one of these. With the new system you can register as many listeners as you like.

    1. I get the impression that you don’t like the new system. I think if you try it you will come to the conclusion that it’s much more flexible. Not to mention your assessment of 1 line vs five has some bad math. Your onRelease is defining a function which is equivalent to the handler function assigned to the AS3 listener. So really it’s only one more line.

Leave a Reply

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