[SOLVED]How to stop application from running when it loses focus

hi there,
I need help with stopping the application from running when it loses focus or when it is minimized.
like Zuma back in the days.
on c# it would be something like :

public void checkState (object sender, EventArgs e)
{
if (WindowState == formWindowState.Minimized)
{
//here comes the boom
}
}

so I was thinking… maybe a window.addEventListener(FocusEvent.losefocus…) or window.addEventListener(Event.deactivate…) but that was me just wishfulthinking…
then I saw Lib.application.onDeactivate but I don’t know how to used it.
any idea would help.

Have you tried something like this?

stage.addEventListener(Event.DEACTIVATE, pause);
stage.addEventListener(Event.ACTIVATE, unpause);

ohhh man! I thought I needed something superior to the stage for it to work.
Thanks, let me try

Wonderfull, it works just like I wanted it to and moreover ^^I can even use FocusEvent.FOCUS_OUT
thousand thanks ^^

Even if I don’t handle ACTIVATE/DEACTIVATE events, when my game loses the focus it pauses: how can avoid this?
Can I override the responsible functions handling these events?

Are you using HaxeFlixel? That doesn’t normally happen in OpenFL, unless you’re talking about Android/iOS.