0
votes

So i am making a game using the Flashpunk framework for AS3, and i can't seem to figure out how to terminate the program execution when the user clicks an exit button. I have tried using both System.exit(0) and fscommand("quit"), but neither of these work in the release build (the former only works in debug mode, the latter doesn't work at all). Does anyone know how to code an exit button in Flashpunk?

Here is my code:

import flash.system.*;
public class Story extends World 
{
    var btnDone:Button = new Button(FP.screen.width * 9 / 10, FP.screen.height * 9 / 10, btnDonePressed, "End", { size: 50, color: 0xFFFFFF } );
    btnDone.setCentered(true);
    add(btnDone);
}
private function btnDonePressed():void
{
    System.exit(0);
    fscommand("quit");
}
2
What are you publishing this game as? a SWF in the browser? Standalone EXE/.app? AIR? If you're targetting AIR, fscommand is a quite out of date. - bigp

2 Answers

0
votes

You can use fscommand("quit") on your button. But to make it work you need to import the fscommand at the top of your code import flash.system.fscommand;.

Also you can use System.exit(0) by importing import flash.system.System; at the top of your code.

0
votes

If you're targeting your Flashpunk game to Adobe AIR, then you should try:

NativeApplication.nativeApplication.exit(); //Small "n" on the second nativeApplication

Reference: Air equivalence for fscommand("quit")