Question

When working with NativeWindow's in AIR, can you get an event everytime the window is minimized / unminimized? I tried hooking up with DisplayStateChanged but its not firing when the window is minimized. Do you know how to get such an event?

I'm on Windows 7, 32-bit, and I'm running AIR 3.5.

This is the init code:

        var init:NativeWindowInitOptions = new NativeWindowInitOptions();
        init.maximizable = true;
        init.resizable = true;
        init.type = NativeWindowType.NORMAL;
        init.minimizable = true;
        window = new NativeWindow(init);
        window.alwaysInFront = true;
        window.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, dispChange, false, 0, true);

And this is the handler:

    private function dispChange(e:NativeWindowDisplayStateEvent):void {


        // if minimized / un-minimized
        if (e.beforeDisplayState == NativeWindowDisplayState.NORMAL && e.afterDisplayState == NativeWindowDisplayState.MINIMIZED) {
            trace("MINIMIZED!");

        }else if (e.beforeDisplayState == NativeWindowDisplayState.MINIMIZED && e.afterDisplayState == NativeWindowDisplayState.NORMAL) {
            trace("Un-MINIMIZED!");

        }
    }
Était-ce utile?

La solution 3

The closest thing I could get to a minimized event was the activate events. Whenever the user clicks outside the app, that window gets deactivated. You can then minimize the window automatically using minimize(). But the deactivated event is also called when the user minimizes the window / switches to another. And when the user switches back you get a call to activate.

window.addEventListener(Event.ACTIVATE, dispActive, false, 0, true);
window.addEventListener(Event.DEACTIVATE, dispDective, false, 0, true);

private function dispActive(e:Event):void {
    // un-minimized
}
private function dispDective(e:Event):void {
    // deactivated .. minimize again to be sure
    window.minimize();
}

Autres conseils

Is the window actually minimizable (check window.minimizable, not just the init setting)?

I would also like to know the results of:

if (e.beforeDisplayState == NativeWindowDisplayState.MINIMIZED) trace("min before");

if (e.afterDisplayState == NativeWindowDisplayState.MINIMIZED) trace("min after");

I would also want to know the results of the 'weak reference' comment above. This affects garbage collection, so is always a good thing to test.

the following works fine on Windows 7 64-bit with AIR 3.3 / Flash Player 11.3.

import flash.display.NativeWindowDisplayState;
import flash.events.NativeWindowDisplayStateEvent;

~

stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, displayStateChangeEventHandler);

~

private function displayStateChangeEventHandler(event:NativeWindowDisplayStateEvent):void
{
    switch (stage.nativeWindow.displayState)
    {
        case NativeWindowDisplayState.MINIMIZED:    trace("window was minimized");
                                                    break;

        case NativeWindowDisplayState.NORMAL:       trace("window is normal");
    }
}

I'm getting events for minimize / unminimize. I'm building an AIR 3.5 app.

window = stage.nativeWindow;
window.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, dispChange, false, 0, true);

function dispChange(e:Event):void {
        minimized = (window.displayState == "minimized");
        if (minimized) {
            trace("minimized!")
        }else {
            trace("UN-minimized!")
        }
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top