How to create exit button in Flash application
Asked Answered
A

5

5

I'm creating a Flash Application that will be exported in exe format and it's not going to run in browser. I want to add an exit button inside stage but I don't know how to do that with ActionScript 3.

I remember that it was possible with fscommand in ActionScript 2 but it's not working in AS3.

I've searched everywhere but everyone is trying to close a popup or tab or window all in browser environment not a Flash app.

Acosmism answered 26/1, 2012 at 16:49 Comment(0)
L
10

Why would use a .exe format when you can now export as3 application as AIR? BUT If you still want the exe, I think that this will work

 import flash.system.fscommand;

 //Then you can use the following function for the button click handler:

 private function clickHandler(event:MouseEvent):void {
      fscommand("quit");
 }

If you decide to try the AIR solution, this is the command

 import flash.desktop.NativeApplication;
 nativeApp.nativeApplication.exit();
Libava answered 26/1, 2012 at 16:56 Comment(4)
Umm, actually I have no idea about AIR and I'm a in hurry for completing my project, I will take a look at it later.Acosmism
Can AIR apps run on Mac as well? Do they need to have AIR installed or can you do it form the Flash IDE?Thermic
@PapaDeBeau yes, AIR app run on Mac too. About your second question, I don't understand it completely sorry.Libava
Correction: Last line of code: From nativeApp.nativeApplication.exit(); To Correct code NativeApplication.nativeApplication.exit(); Carri
P
4

It's still an fscommand, but the syntax is different:

import flash.system.fscommand;

btn.addEventListener(MouseEvent.MOUSE_DOWN, closeApp);

function closeApp(event:MouseEvent):void {
    fscommand("quit");
}
Ponderous answered 26/1, 2012 at 16:58 Comment(0)
M
3

System.exit(0); should close a desktop application?

Minimalist answered 26/1, 2012 at 16:54 Comment(2)
This also works. You'll need to import flash.system.System; for it to work, of course.Ponderous
Thank you. System.exit(0) and fscommand("quit") are both working.Acosmism
S
3

Try:

 import flash.system.fscommand;

 function clickHandler(event:MouseEvent):void {
 fscommand("quit");
 }

 btn.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
Skiba answered 26/1, 2012 at 16:55 Comment(0)
S
0
function exitAdobe (event:MouseEvent): void {

NativeApplication.nativeApplication.exit();

}
bt_exit.addEventListener(MouseEvent.CLICK, exitAdobe);

//A melhor forma que encontrei...
Spermatozoon answered 18/6, 2016 at 6:0 Comment(1)
Format your code correctly (must be pushed four spaces to the right) and try to use English.Profanity

© 2022 - 2024 — McMap. All rights reserved.