-1

I have an <mx:Canvas> as my ApplicationMainView.mxml, and am trying to access all current popups I have opened through it. Is there a way to do this outside of looking through every child view component manually?

My goal is to show the login view again at a certain point, but there are popups that will show over the login view and the user can still interact with. I want to try something roughly as follows:

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;
}
}
Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78

1 Answers1

1

I think this code will help you.

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 />

Get all popups

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