Flex popup manager, mousedown outside popup removes popup

If you create a popup using:

PopUpManager.addPopUp (popup, this, false); PopUpManager.bringToFront (popup);

It will create a popup and display it on top of any other visual part. I have one problem. This popup should remain even when the user interacts with the background.

I would use modal, but I need the ability to interact with the back. Any way to tell the popup manager not to remove the popup when the user clicks on it?

Thank!

+3
source share
1 answer

, ( Flex 4, , , Flex 3):

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;

import mx.core.mx_internal;
import mx.managers.ISystemManager;
import mx.managers.systemClasses.ActiveWindowManager;

use namespace mx_internal;

public class PopupHelper
{
    private var popup : DisplayObject;
    private var systemManager : ISystemManager;
    public function PopupHelper(popup : DisplayObject, systemManager : ISystemManager) : void
    {
        this.popup = popup;
        this.systemManager = systemManager;
    }
    public function forceToFront() : void
    {
        systemManager.addEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
        popup.addEventListener(Event.REMOVED_FROM_STAGE, onPopupRemoved)
    }
    private function onSystemMouseDown(e : MouseEvent) : void
    {
        bringToFront(popup);
    }
    private function onPopupRemoved(e : Event) : void
    {
        popup.removeEventListener(Event.REMOVED, onPopupRemoved);
        systemManager.removeEventListener(MouseEvent.MOUSE_DOWN, onSystemMouseDown);
    }
    private function bringToFront(popup : DisplayObject) : void
    {
        var windowManager : ActiveWindowManager = systemManager.getImplementation("mx.managers::IActiveWindowManager") as ActiveWindowManager;
        var index : int = systemManager.getChildIndex(popup); 
        var newIndex : int = index;
        var n : int = windowManager.forms.length;
        for (var j : int = 0; j < n; j++)
        {
            var f : DisplayObject = windowManager.forms[j];
            if (systemManager.contains(f))
                if (systemManager.getChildIndex(f) > index)
                    newIndex = Math.max(systemManager.getChildIndex(f), newIndex);
        }
        if (newIndex > index)
        {
            systemManager.setChildIndex(popup, newIndex);
        }
    }
}

>

:

        import helperClasses.PopupHelper;
        import mx.managers.PopUpManager;

        import spark.components.TitleWindow;

        public function showPopup() : void
        {   
            var popup1 : TitleWindow = new TitleWindow();
            popup1.title = "Popup 1";
            new PopupHelper(popup1, systemManager).forceToFront();
            var popup2 : TitleWindow = new TitleWindow();
            popup2.title = "Popup 2";
            PopUpManager.addPopUp(popup1, this, false);
            PopUpManager.addPopUp(popup2, this, false);
            PopUpManager.bringToFront(popup1);
            popup1.x = 20;
            popup1.y = 20;
        }

>

+2

Source: https://habr.com/ru/post/1796322/


All Articles