如何关闭Flex中的所有弹出窗口?

发布于 2024-11-28 19:44:44 字数 70 浏览 1 评论 0原文

我想通过按下按钮来显示图像上的所有弹出窗口(已经弹出并单独关闭),并希望在按下另一个按钮时关闭所有这些窗口。任何帮助表示赞赏。

I want to show all popup windows(already popped up and closed individually) on an image by pressing a button press and want to close all those windows on another button press. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

季末如歌 2024-12-05 19:44:44

试试这个:

package com.devahead.utils
{
    import flash.display.DisplayObject;

    import mx.collections.ArrayCollection;
    import mx.core.Application;
    //import mx.core.FlexGlobals; // NOTE: use this import for Flex 4.x and higher
    import mx.core.IChildList;
    import mx.core.UIComponent;
    import mx.managers.PopUpManager;

    public class PopUpUtils
    {
        /**
         * Returns all the popups inside an application. Only the popups whose base
         * class is UIComponent are returned.
         *
         * @param applicationInstance
         *   Application instance. If null, Application.application is used.
         * @param onlyVisible
         *   If true, considers only the visible popups.
         * @return All the popups in the specified application.
         */
        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: UIComponent in allPopups)
            {
                PopUpManager.removePopUp(currPopup);
            }

            return allPopups;
        }
    }
}

我从以下内容中得到它:
http://www.devahead.com/blog/2009/12/getting-all-the-popups-in-a-flex-application/" devahead.com/blog/2009/12/getting-all-the-popups-in-a-flex-application/

Try this:

package com.devahead.utils
{
    import flash.display.DisplayObject;

    import mx.collections.ArrayCollection;
    import mx.core.Application;
    //import mx.core.FlexGlobals; // NOTE: use this import for Flex 4.x and higher
    import mx.core.IChildList;
    import mx.core.UIComponent;
    import mx.managers.PopUpManager;

    public class PopUpUtils
    {
        /**
         * Returns all the popups inside an application. Only the popups whose base
         * class is UIComponent are returned.
         *
         * @param applicationInstance
         *   Application instance. If null, Application.application is used.
         * @param onlyVisible
         *   If true, considers only the visible popups.
         * @return All the popups in the specified application.
         */
        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: UIComponent in allPopups)
            {
                PopUpManager.removePopUp(currPopup);
            }

            return allPopups;
        }
    }
}

I got it from the following:
http://www.devahead.com/blog/2009/12/getting-all-the-popups-in-a-flex-application/

怪我闹别瞎闹 2024-12-05 19:44:44

试试这个:

for (var i:int = systemManager.popUpChildren.numChildren - 1; i >= 0; i--)
{
    var popup:IFlexDisplayObject = IFlexDisplayObject(systemManager.popUpChildren.getChildAt(i));
    PopUpManager.removePopUp(popup);
}

Try this:

for (var i:int = systemManager.popUpChildren.numChildren - 1; i >= 0; i--)
{
    var popup:IFlexDisplayObject = IFlexDisplayObject(systemManager.popUpChildren.getChildAt(i));
    PopUpManager.removePopUp(popup);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文