Reputation: 39
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?
Upvotes: 1
Views: 52801
Reputation: 1
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.
Upvotes: 0
Reputation: 5554
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
.
Upvotes: 1
Reputation: 1996
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");
}
Upvotes: 0