在AIR中使用NativeWindow
's时,每次窗口最小化/非最小化时都可以获得事件吗?我试着与DisplayStateChanged
挂钩,但当窗口最小化时,它不会开火。你知道如何举办这样的活动吗?
我用的是32位的Windows 7,运行的是AIR 3.5。
初始化代码:
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);
这是处理程序:
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!");
}
}
以下内容适用于Windows 7 64位,安装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");
}
}
窗口实际上是可最小化的(检查window.minimizable
,而不仅仅是init
设置)?
我还想知道:
if (e.beforeDisplayState == NativeWindowDisplayState.MINIMIZED) trace("min before");
if (e.afterDisplayState == NativeWindowDisplayState.MINIMIZED) trace("min after");
我还想知道上面的"弱引用"注释的结果。这会影响到垃圾收集,所以最好进行测试。
我能得到的最接近最小化事件的东西是激活事件。每当用户在应用程序外点击时,该窗口就会被停用。然后可以使用minimize()自动最小化窗口。但是,当用户最小化窗口/切换到另一个窗口时,也会调用deactivated事件。当用户切换回来时,你会收到一个激活电话。
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();
}
我正在获取最小化/取消最小化的事件。我正在构建一个AIR 3.5应用程序。
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!")
}
}