Flex :找到最上面的弹出窗口
使用 PopupManager 可以添加/创建/删除新的弹出窗口。但我无法找到一种方法来获得最顶部的弹出窗口而不覆盖此类(这是您想要为大型 Flex 应用程序做的事情)。
到目前为止,我找到了这个解决方案,这更适合解决问题。因此,如果有人有更好的解决方案,我将非常乐意阅读它。
假设您使用参数 PopUpManagerChildList.POPUP
调用 addPopup/createPopup,例如:
PopUpManager.createPopUp(parent,MyPopupClass,true,PopUpManagerChildList.POPUP);
该函数将返回最上面的弹出窗口:
private function getTopMostPopup():void
{
var childList:IChildList = Application.application.systemManager.popUpChildren;
for (var i:int = childList.numChildren - 1; i > 0; i--)
{
var child:DisplayObject = childList.getChildAt( i );
if (child is Container)
return child;
}
return null;
}
Application.application.systemManager.popUpChildren
包含使用 PopupManager 显示的所有 DisplayObject。但是组件的许多 itemRenderer 可能会在此列表中,即使在屏幕中不可见。这就是为什么我的函数获得从 Container 继承的最后一个子级(您的弹出窗口必须从 Container 继承)。
With the PopupManager it's possible to add/create/remove a new popup. But i can't find a way to get the top most popup without overriding this class (which something you want to do for a big Flex application).
So far I found this solution, which is more kinna of work around. So if any body has a better solution, i will be pretty much happy to read it.
Assuming the you call the addPopup/createPopup with the parameter PopUpManagerChildList.POPUP
, example :
PopUpManager.createPopUp(parent,MyPopupClass,true,PopUpManagerChildList.POPUP);
The this function will return the top most popup:
private function getTopMostPopup():void
{
var childList:IChildList = Application.application.systemManager.popUpChildren;
for (var i:int = childList.numChildren - 1; i > 0; i--)
{
var child:DisplayObject = childList.getChildAt( i );
if (child is Container)
return child;
}
return null;
}
Application.application.systemManager.popUpChildren
contains all the DisplayObject displayed with PopupManager. But many of the itemRenderers of your components could be in this list eventhough there are not visible in the screen. This is why my function get the last child inheriting from Container (your popup must inherit from Container).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是创建一个自定义弹出管理器。为了它,我把我的给你。我没有“最顶层”功能,但您可以轻松添加它。这是课程:
这应该可以帮助您入门。从这里开始,如果您想实现您的函数,您可以创建一个数组,在创建/删除弹出窗口时添加/删除弹出窗口(每个新弹出窗口都会添加到索引 0),并且该函数将仅返回索引 0 处的弹出窗口。
理解者?
What you need to do is create a custom popup manager. For the sake of it, I'll give you mine. I don't have the 'topmost' function, but you could easily add it. Here's the class:
This should get you started. From here, if you want to implement your function, you could create an array that would add/remove popup when you create/remove them (every new popup gets added to index 0) and the function would just return the popup at index 0.
Comprender?