NativeWindow creationComplete and closing events

I’m porting an AS3/Spark/Air app that supports multiple windows based on spark.components.Window. Working with the OpenFL NativeWindow, I’m currently stuck trying to understand how to detect two events. The Spark equivalents are:

  1. creationComplete: when the window is available for the first time. The available NativeWindow events (active, etc.) seem to reoccur throughout the app lifetime. I guess I could set a firstActivate flag if that would be the recommendation.

  2. closing: before the window closes in order to intervene in case there is unsaved work. I see the advice in the NativeWindow doc to “manually dispatch a closing event”, but the question is “Where?” If the window is closed manually by the user clicking the close box, there does not seem to be an opportunity to intervene before OpenFL NativeWindow.window_onClose gets called, cleans up, and dispatched it’s own close event. Adding my own lime close event listener to the private NativeWindow.window.__window or overriding the private NativeWindow.window_onClose don’t seem to be options either.

Thanks, any help appreciated.

FlexEvent.CREATION_COMPLETE is an event that gets dispatched by Flex components after they validate for the first time. Your firstActivate flag is probably the best solution as a replacement for that.

It appears that OpenFL does not yet implement Event.CLOSING for NativeWindow, so there is currently no way to cancel it. It appears that Lime’s Window.onClose event can be canceled, though, so it should be possible to implement that properly in a future OpenFL update. I’ll try to find some time to add it.

Thanks. Let me know if I can be of any help.

I have implemented Event.CLOSING for NativeWindow in OpenFL’s 9.5.0-dev branch.

It will be included in a future update. In the meantime, you can use nightly builds of openfl-haxelib from the 9.5.0-dev branch: