Exit button for ActionScript 3.0

actionscript-3

I'm trying to make a flash video that has an 'exit' button which closes the movie when the user clicks it. Originally I had this code for it:

fscommand("quit"); 

But then whenever I published the movie as an EXE file (its going to be a catalog index page in an auto-run CD so I think it has to be an EXE) that code causes the movie to close automatically. I would click the EXE file, the screen would flash and then close. When I took that code out of the Actions for that button's layer, it worked fine (didn't close) but now I don't have a quit command. Unless I did something wrong?

So is there another type of command for AS3.0 to create an 'exit' button? Or is there something I'm missing in this code, like am I supposed to add something else?

Best Solution

In as3, you must use events and event handlers like this :

import flash.events.MouseEvent;

exitButton_mc.addEventListener(MouseEvent.CLICK, function()
{
        fscommand("quit");
}

In as2, you can code like this :

exitButton_mc.onRelease = function()
{
    fscommand("quit");
}

Where exitButton_mc is your button and you have given this as its instance name in the properties panel. If you write the code fscommand("quit");, in the timeline itself, it will get executed and close the EXE.

On a side note, I read some where that the best approach to code in Flash is to keep to layers at the top named _actions and _labels which will not contain any UI elements, but all the as code will be in the _actions layer and labels for keyframes will be kept in _labels.

Related Question