How to exit Haxe/OpenFL program?
Asked Answered
L

1

7

I am making a game using Haxe, OpenFL (Formerly NME) and HaxeFlixel.

However, problem is, I can't seem to find a good way to make a Flixel button that will shutdown the game when pressed. I was planning to make a "quit" button on the main menu.

Is there any simple method to do so or is it impossible?

Levileviable answered 5/7, 2013 at 15:5 Comment(0)
D
14

It depends on the compilation target: I'm going to assume you're compiling to CPP (Windows EXE). In which case you should just be able to use the following:

import flash.system.System; // Or nme.system.System if you're using NME

...

// in your FlxButton callback:
System.exit(0);

I can't test right now so I don't know what effect this would have in Flash (i.e. you may have to wrap it in a conditional compilation flag for cpp), but I do know that it won't work for iOS.

Darkling answered 8/7, 2013 at 13:31 Comment(1)
Just tested it on both Flash and Windows build settings, works on both. I do not plan to compile for iOS, so it's good enough for me :)Levileviable

© 2022 - 2024 — McMap. All rights reserved.