PlayBook: Exit From an App Using ActionScript


Posted:   |  More posts about PlayBook ActionScript3

In a previous post I talked about several non-obvious gestures that let you exit from an app but, if you're a developer, you'll sometimes want to provide a Close button or some other way for users to edit more directly.

The most straightforward way is stage.nativeWindow.close(). This is actually a call that must be made from within a method in your main Sprite class, or any other suitable DisplayObject since it references the read-only stage property.

The actual call is to the NativeWindow.close() method. There are certain events associated with closing a window, or deactivating it, which I've covered in a previous post.

To summarize, here's a snippet to give yourself a Close button in your Sprite:

    ...
    var closeBut:LabelButton = new LabelButton();
    closeBut.label = "Close";
    closeBut.addEventListener(MouseEvent.CLICK, closeApp);
}

private function closeApp(event:MouseEvent):void {
    stage.nativeWindow.close();
}
Comments powered by Disqus