Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Pop up registering in a multicore version  (Read 8458 times)
xAvIxXxXx
Newbie
*
Posts: 4


View Profile Email
« on: July 15, 2009, 07:58:39 »

Hi,

I have a problem of registering a popup in the multicore version.
The launching of the popup is done in a Module, but there are a lot of components contained in the module and it is not very clean to access the Module (to retrieve the moduleID) with the parent.parent...

I would like to use the popup class showed under but I don't know how to retrieve the moduleUid.
Does anyone know how to do that ?

Thanks in advance.
Xavi

:
package com....
{
    import flash.display.DisplayObject;
    import flash.display.Sprite;

    import mx.core.Application;
    import mx.core.IFlexDisplayObject;
    import mx.managers.PopUpManager;

    import org.puremvc.as3.multicore.patterns.facade.Facade;

    /**
     * Used to handle popup opening controling registering and unregistering mediators
     *
     * @author
     */

    public class PopManager extends PopUpManager
    {
        private static var popupList:Array=new Array();

        /**
         * Opens a popup window. Window component is created and mediator is assigned to it.
         * Targeted for PureMVC multicore so method requires moduleId to be passed
         */
        public static function openPopUpWindow(ComponentClass:Class, MediatorClass:Class, moduleUid:String, modal:Boolean=true, parent:DisplayObject=null):IFlexDisplayObject
        {
            if (parent == null){
                parent=Application.application as DisplayObject;
            }
            var window:IFlexDisplayObject=PopUpManager.createPopUp(parent, ComponentClass, modal);
            var obj:Facade=Facade.getInstance(moduleUid)as Facade;

            obj.registerMediator(new MediatorClass(window));
            PopUpManager.centerPopUp(window);
            return window;
        }

        /**
         *  Removes PopUp window and unregisteres associated mediator
         */
        public static function closePopUpWindow(window:IFlexDisplayObject, mediatorName:String, moduleUid:String):void
        {
            PopUpManager.removePopUp(window);
            Facade.getInstance(moduleUid).removeMediator(mediatorName);
        }

        /**
         *
         * Tries to retrieve popup window from the list of popups already opened. If there is no window opened with
         * provided mediator name associated with it, a new one is created and displayed.
         */
        public static function retrievePopUp(ComponentClass:Class, MediatorClass:Class, mediatorName:String, moduleUid:String, modal:Boolean=true):IFlexDisplayObject
        {
            if (popupList[mediatorName])
            {
                PopUpManager.addPopUp(popupList[mediatorName]as IFlexDisplayObject, Application.application as Sprite, modal);
                PopUpManager.bringToFront(popupList[mediatorName]);
            }
            else
            {
                popupList[mediatorName]=openPopUpWindow(ComponentClass, MediatorClass, moduleUid, modal)
            }
            return popupList[mediatorName];
        }

        /**
         *  Removes popup from display list. The actual popup object still exists in the list and can be retrieved
         */
        public static function hidePopUp(window:IFlexDisplayObject, mediatorName:String):void
        {
            PopUpManager.removePopUp(window);
        }

        /**
         * Removes the popup completle. Also unregisters mediator.
         */
        public static function destroyPopUp(window:IFlexDisplayObject, mediatorName:String, moduleUid:String):void
        {
            closePopUpWindow(window, mediatorName, moduleUid);

            if (popupList[mediatorName])
            {
                popupList[mediatorName]=null;
            }
        }
    }

}
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: July 15, 2009, 09:43:51 »

Are you looking for the multitonKey (the name of the core as registered with the facade when getInstance is called), perhaps? If so, you can just reference the multitonKey property of whatever Command, Mediator or Proxy you're working with.

-=Cliff>
Logged
xAvIxXxXx
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: July 22, 2009, 07:51:10 »

Thanks for your quick answer Cliff.

No, I search the identifier of the module parent of the container. To solve my problem for the moment, i access the moduleParent thanks to the code (component.parent.parent.parent... as Module).ID

But is that correct to use the multitonKey of a command or a mediator or a proxy to register the popupMediator instance ? The multitonKey are the same for all the object within a module ?

Xavi
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: July 26, 2009, 08:37:05 »

:
(component.parent.parent.parent... as Module).ID
Run away! Run away!  :P

Don't do that. It is waaaaay to brittle. If you insert another component in the hierarchy, it breaks. It assumes too much knowledge of the hierarchy.

Instead, register a mediator for the module itself, and expose a getModuleID method on it. Then when you need to know the Module's ID just retrieve the ModuleMediator and call getModuleID. This lets you get to that ID without knowing or caring where your component is in the view hierarchy.

-=Cliff>
Logged
Pages: [1]
Print