如果您通过以下方式创建弹出窗口:
PopUpManager.addPopUp(popup,this,false); PopUpManager.bringToFront(popup);
它将创建一个弹出窗口并将其置于任何其他视觉片段之上。我有一个问题。即使用户与后台进行交互,此“弹出窗口”也需要保持正常状态。
我会使用模态,但我需要能够与背面进行交互。有什么方法可以告诉弹出管理器在用户点击它时不要删除弹出窗口吗?
谢谢!
答案 0 :(得分:2)
这是一个帮助你的帮助程序类(仅在Flex 4中测试过,但也可能在Flex 3中进行了更改):
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.core.mx_internal;
import mx.managers.ISystemManager;
import mx.managers.systemClasses.ActiveWindowManager;
use namespace mx_internal;
public class PopupHelper
{
private var popup : DisplayObject;
private var systemManager : ISystemManager;
public function PopupHelper(popup : DisplayObject, systemManager : ISystemManager) : void
{
this.popup = popup;
this.systemManager = systemManager;
}
public function forceToFront() : void
{
systemManager.addEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
popup.addEventListener(Event.REMOVED_FROM_STAGE, onPopupRemoved)
}
private function onSystemMouseDown(e : MouseEvent) : void
{
bringToFront(popup);
}
private function onPopupRemoved(e : Event) : void
{
popup.removeEventListener(Event.REMOVED, onPopupRemoved);
systemManager.removeEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
}
private function bringToFront(popup : DisplayObject) : void
{
var windowManager : ActiveWindowManager = systemManager.getImplementation("mx.managers::IActiveWindowManager") as ActiveWindowManager;
var index : int = systemManager.getChildIndex(popup);
var newIndex : int = index;
var n : int = windowManager.forms.length;
for (var j : int = 0; j < n; j++)
{
var f : DisplayObject = windowManager.forms[j];
if (systemManager.contains(f))
if (systemManager.getChildIndex(f) > index)
newIndex = Math.max(systemManager.getChildIndex(f), newIndex);
}
if (newIndex > index)
{
systemManager.setChildIndex(popup, newIndex);
}
}
}
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.core.mx_internal;
import mx.managers.ISystemManager;
import mx.managers.systemClasses.ActiveWindowManager;
use namespace mx_internal;
public class PopupHelper
{
private var popup : DisplayObject;
private var systemManager : ISystemManager;
public function PopupHelper(popup : DisplayObject, systemManager : ISystemManager) : void
{
this.popup = popup;
this.systemManager = systemManager;
}
public function forceToFront() : void
{
systemManager.addEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
popup.addEventListener(Event.REMOVED_FROM_STAGE, onPopupRemoved)
}
private function onSystemMouseDown(e : MouseEvent) : void
{
bringToFront(popup);
}
private function onPopupRemoved(e : Event) : void
{
popup.removeEventListener(Event.REMOVED, onPopupRemoved);
systemManager.removeEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
}
private function bringToFront(popup : DisplayObject) : void
{
var windowManager : ActiveWindowManager = systemManager.getImplementation("mx.managers::IActiveWindowManager") as ActiveWindowManager;
var index : int = systemManager.getChildIndex(popup);
var newIndex : int = index;
var n : int = windowManager.forms.length;
for (var j : int = 0; j < n; j++)
{
var f : DisplayObject = windowManager.forms[j];
if (systemManager.contains(f))
if (systemManager.getChildIndex(f) > index)
newIndex = Math.max(systemManager.getChildIndex(f), newIndex);
}
if (newIndex > index)
{
systemManager.setChildIndex(popup, newIndex);
}
}
}
这是一个测试示例:
import helperClasses.PopupHelper;
import mx.managers.PopUpManager;
import spark.components.TitleWindow;
public function showPopup() : void
{
var popup1 : TitleWindow = new TitleWindow();
popup1.title = "Popup 1";
new PopupHelper(popup1, systemManager).forceToFront();
var popup2 : TitleWindow = new TitleWindow();
popup2.title = "Popup 2";
PopUpManager.addPopUp(popup1, this, false);
PopUpManager.addPopUp(popup2, this, false);
PopUpManager.bringToFront(popup1);
popup1.x = 20;
popup1.y = 20;
}