Event.DEACTIVATE and Event.ACTIVATE are not firing on Windows target

I had this problem before, but I was able to solve it for legacy mode using this:

Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onPause);
Lib.current.stage.addEventListener(FocusEvent.FOCUS_IN, onResume);

Unfortunately, it doesn’t work as expected anymore. (cause music lag here)
Any chance to fix this?
If someone is minimize my game, I need it to stop playing background music.

Thank you!


1 Like

Amazing! Thank you! :slight_smile:

Well, just discovered, it works only half way.
If I minimize/restore my app - it works.
But if I just switch to another app (Alt-TAB) - it does not work.

I did some tests, in order for Event.ACTIVATE and Event.DEACTIVATE to work like in Flash they should be dispatched in onWindowFocusIn and onWindowFocusOut respectively.
All other functions, like onWindowActivate, onWindowMinimize, etc. are not required to dispatch these events.

The Event.DEACTIVATE and Event.ACTIVATE events are often used for completely putting an application to sleep. Do you think this should always be the behavior when an application loses focus, but is still active?

Flash Player might be a bit different than Adobe AIR in this regard, and perhaps different, too, than what we want.

If you think of a website, you get a DEACTIVATE when you leave the browser tab, but not if you scroll the page or click on something other than Flash on the page. In that case, you’ve lost focus, but the Flash content is still active

I’m using ACTIVATE and DEACTIVATE in Flash, and it works this way:

  • when you click something other on the page, stage receives DEACTIVATE event.
  • same for AIR, if you simply switch to another app, you receive DEACTIVATE event.

I don’t say, it’s the right way, but that’s the way it works in Flash.

That’s what I’m used to, certainly.

https://github.com/openfl/openfl/commit/9e1f397de764a5f2f15d0058647d4704a79a3f32 :slight_smile: