x2f
x2f

Reputation: 185

Is there an atexit() equivalent for Haxe?

Is there a way to register a function which will be run at the end of a Haxe program (or an equivalent technique)?

Upvotes: 3

Views: 116

Answers (1)

Mark Knol
Mark Knol

Reputation: 10143

I don't think there is one in the Haxe Standard Library. For example this wouldn't make sense for JavaScript or the Flash target.

In case of JavaScript you could listen to the window onbeforeclose event.

In case of Flash you could listen to deactivate

On linear platforms; you could create your own "lifecycle" by doing this:

class Test {
    static function main() {
        onStart();
        new MyApplication();
        onExit();
    }

    static function onStart() {
        trace("onStart");
    }

    static function onExit() {
        trace("onExit");
    }
}

http://try.haxe.org/#1e5C6 But maybe I'm thinking to simple.

If you are using openFL, this might interest you: http://www.openfl.org/archive/community/programming-haxe/how-to-be-notifed-and-the-application-quits/

Which platform are you targetting?

Upvotes: 1

Related Questions