【问题标题】:How can I prevent items behind a pop-up titlewindow from receiving mouse events?如何防止弹出标题窗口后面的项目接收鼠标事件?
【发布时间】:2011-08-16 21:24:37
【问题描述】:
我有一个Popup 皮肤TitleWindow 用作弹出窗口,但它后面的项目正在接收鼠标悬停和单击事件。是否有一个选项可以让我防止鼠标事件发生在窗口的主要内容组后面?
编辑:澄清一下-我不是在问如何制作窗口模式。当用户单击contentGroup 皮肤部分的区域时,弹出窗口后面的项目——不是在主窗体上而是在侧面,而是在后面和隐藏的后面——正在接收鼠标事件。如果用户单击该组中的项目,则不会发生这种情况,但轻微的未命中可能会触发意外的背景按钮。
【问题讨论】:
标签:
apache-flex
flex-spark
【解决方案1】:
当您创建弹出集modal=true 时。比如:
var pop:MyPopUpClass = PopUpManager.createPopUp(parent, MyPopUpClass, true) as MyPopUpClass;
【解决方案2】:
您需要将弹出窗口设为模态窗口。当你制作模态的东西时,这意味着窗口(警报、弹出窗口、标题窗口等)将保持在顶部,屏幕的其余部分将冻结,直到顶部窗口关闭。
“PopUpManager 还提供了模态,使弹出窗口下方的窗口无法接收鼠标事件,并且还提供了用户在窗口外单击鼠标时的事件,以便开发人员可以选择关闭窗口或警告用户。”
modal 的默认值为false。您可以通过在addPopup 或createPopup 时传递true 将其设置为true
public static function addPopUp(window:IFlexDisplayObject, parent:DisplayObject, modal:Boolean = false, childList:String = null):void
public static function createPopUp(parent:DisplayObject, className:Classe, modal:Boolean = false, childList:String = null):IFlexDisplayObject
【解决方案3】:
我通过替换这个解决了这个问题:
<s:SparkSkin ...>
<s:Rect height="{hostComponent.height}" radiusX="10" width="{hostComponent.width}">
<s:fill>
<s:SolidColor color="#F5F4EB"/>
</s:fill>
</s:Rect>
<!-- header, move area, close button and other details -->
<s:Group id="contentGroup"
top="40"
left="10"
right="10"
bottom="10">
</s:Group>
</s:SparkSkin>
有了这个:
<s:SparkSkin ...>
<s:Rect height="{hostComponent.height}" radiusX="10" width="{hostComponent.width}">
<s:fill>
<s:SolidColor color="#F5F4EB"/>
</s:fill>
</s:Rect>
<!-- header, move area, close button and other details -->
<s:Group top="40"
left="10"
right="10"
bottom="10">
<s:Rect top="0"
left="0"
right="0"
bottom="0">
<s:fill>
<s:SolidColor color="0xF5F4EB" />
</s:fill>
</s:Rect>
<s:Group id="contentGroup"
top="0"
left="0"
right="0"
bottom="0">
</s:Group>
</s:Group>
</s:SparkSkin>
在组后面创建一个矩形对象使其正常接受点击事件。
【解决方案4】:
如果您不是在寻找modal 的答案,那么我所能推荐的就是在弹出窗口打开时删除所有相关的侦听器,并在弹出窗口被删除时重新添加它们。
x.removeEventListener(MouseEvent.CLICK...
PopUpManager.addPopup(...
onClose(...
x.addEventListener(MouseEvent.CLICK...