New Buttons in AS3

OK, so if you’re working in Actionscript 3 then you’ve realized that making a button function is a totally different story now.

First, you CANNOT put code directly onto a button anymore. Like this:

on (release)
 {
        nextScene();
}

Nor can you call it by name and tag “onRelease” to the end of it.Like this:

quit_btn.onRelease = function()
{
trace(“you just released the quit button”);
}

This is the ONLY way to make a button work in AS3:

quit_btn.addEventListener(MouseEvent.MOUSE_UP, scrollUp);

i just added a function that listens for a mouse up event. when the mouse is released it will call the function called scrollUp.

Listeners have taken over AS3 so i suggest you get used to using listeners. Audio, video, and loading all use listeners in AS3.


About this entry