1
votes

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?

3
In an executable, the quit command closes the executable. What behaviour were you expecting? - shanethehat
where did you put this command? in the programming section in the time line of the flash designer or in a as3 file? - duedl0r
the command was on the buttons layer in the Actions area. I have a layer for each object in the video, so I just went to the exit buttons layer, clicked F9 to open the Actions for that layer, and just pasted it in there. I wanted it to work so that when the user clicks the button 'EXIT' the program closes. I was told that command would do that, but aparently it just closed my video altogether the moment it opened. - renBnoto

3 Answers

1
votes

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.

0
votes

If you put this action directly on a timeline, it will fire immediately, so when your exe file starts it will see quit action and close.

You have to create an event listener for your button click and put there fscommand action like this:

myCloseButton.addEventListener(MouseEvent.CLICK, CloseApp);

function CloseApp(e:MouseEvent) {
    fscommand("quit");
}
0
votes
import flash.events.MouseEvent;
import flash.system.fscommand;

exit_button.addEventListener(MouseEvent.CLICK, CloseApp);

function CloseApp(e:MouseEvent) {
    fscommand("quit");
}

Pubblish your flash app. Then run published swf. note: "quit" does not work when test-exporting in Flash. It only works in published swf file.