在flex应用程序中查找所有弹出窗口

时间:2016-01-14 20:14:19

标签: actionscript-3 flex mxml

我有一个<mx:Canvas>作为我的ApplicationMainView.mxml,我正在尝试访问我通过它打开的所有当前弹出窗口。有没有办法在手动查看每个子视图组件之外执行此操作?

我的目标是在某个时刻再次显示登录视图,但是有一些弹出窗口将显示在登录视图上,用户仍然可以与之交互。我想大致尝试以下内容:

ApplicationMainView.mxml

<mx:canvas>

<mx:VBox id="containerBox">
<!--all view stacks-->
</mx:VBox>
</mx:canvas>

AS3

for each(viewChild in containerBox){ 
    if(viewChild.id != "myLoginView"){
       viewChild.visible = false;
}
}

1 个答案:

答案 0 :(得分:1)

我认为此代码会对您有所帮助。

public class PopUpUtils
{
    public function PopUpUtils()
    {
    }
    public static function getAllPopups(applicationInstance: Object = null, onlyVisible: Boolean = false): ArrayCollection
    {
        var result: ArrayCollection = new ArrayCollection();

        if (applicationInstance == null)
        {
            // NOTE: use this line for Flex 4.x and higher
            applicationInstance = FlexGlobals.topLevelApplication;

            // NOTE: use this line for Flex 3.x and lower
            //applicationInstance = Application.application;
        }

        var rawChildren: IChildList = applicationInstance.systemManager.rawChildren;

        for (var i: int = 0; i < rawChildren.numChildren; i++)
        {
            var currRawChild: DisplayObject = rawChildren.getChildAt(i);

            if ((currRawChild is UIComponent) && UIComponent(currRawChild).isPopUp)
            {
                if (!onlyVisible || UIComponent(currRawChild).visible)
                {
                    result.addItem(currRawChild);
                }
            }
        }

        return result;
    }
    /**
     * Checks if an application has visible popups. Only the popups whose base
     * class is UIComponent are considered.
     *
     * @param applicationInstance
     *   Application instance. If null, Application.application is used.
     * @return True if there are visible popups in the specified application,
     *         false otherwise.
     */
    public static function hasVisiblePopups(applicationInstance: Object = null): Boolean
    {
        if (applicationInstance == null)
        {
            // NOTE: use this line for Flex 4.x and higher
            applicationInstance = FlexGlobals.topLevelApplication;

            // NOTE: use this line for Flex 3.x and lower
            //applicationInstance = Application.application;
        }

        var rawChildren: IChildList = applicationInstance.systemManager.rawChildren;

        for (var i: int = 0; i < rawChildren.numChildren; i++)
        {
            var currRawChild: DisplayObject = rawChildren.getChildAt(i);

            if ((currRawChild is UIComponent) && UIComponent(currRawChild).isPopUp
                && UIComponent(currRawChild).visible)
            {
                return true;
            }
        }

        return false;
    }
    /**
     * Closes all the popups belonging to an application. Only the popups
     * whose base class is UIComponent are considered.
     *
     * @param applicationInstance
     *   Application instance. If null, Application.application is used.
     * @return The list of the closed popups.
     */
    public static function closeAllPopups(applicationInstance: Object = null): ArrayCollection
    {
        var allPopups: ArrayCollection = getAllPopups(applicationInstance);

        for each (var currPopup:* in allPopups) //UIComponent
        {
            if (currPopup.id == null) {
                ObjectUtil.getClassInfo(currPopup)
                currPopup.automationOwner == DateField
                flash.utils.getQualifiedClassName(currPopup)
                PopUpManager.removePopUp(currPopup);
            } /*else {
                currPopup.id.displayPopup = false;
            }*/
        }

        return allPopups;
    }
}<br />

获取所有弹出窗口

var arr:ArrayCollection = PopUpUtils.getAllPopups(FlexGlobals.topLevelApplication);