Flex: How would you create a popup (with PopupManager) and react when it's closed?

Quentin's Avatar


09 Jul, 2010 01:57 PM

I'm new to Robotlegs so my question might be dumb or simple but I've look around and couldn't find any answer to my specific needs...

I have a view with a button on it that is supposed to pop a TitleWindow up (it's an "edit window": you select something on a list, click edit, and get this window where you can rename the item you selected). After reading posts and FAQs I decided to do this with a custom event and mapping a command to it. The event is fired, the mapping executes the command that adds the popup, the popup is filled with data bundled in the event's payload... And that works pretty well!
This TitleWindow has some kind of an OK button in it so I now wonder how to close the popup when this OK thing is clicked and to update the selected item (supposed to be renamed). What would be the right way to do that? Would create another custom event and another command? And how would you access the popup's data (like the new name)?

I hope someone out there understands my needs and can help a bit!

  1. 1 Posted by Jason Dias on 09 Jul, 2010 06:30 PM

    Jason Dias's Avatar


    Yes the popup should dispatch another event to save the data to a model
    and/or update the view, you could also close the popup based on this event.


  2. 2 Posted by Quentin on 12 Jul, 2010 08:26 AM

    Quentin's Avatar

    Yes OK, I can do that...
    But my main question is: where and when do we save a reference to the object being edited? In the event, in the popup instance, somewhere else? And how do we access the popup's data? Does the event have to carry all this?
    That seems OK to me but I'd like to be sure I'm doing things like they're supposed to be done... Still learning!

  3. 3 Posted by Jason Dias on 12 Jul, 2010 08:34 AM

    Jason Dias's Avatar

    Assuming the object being edited is a VO, then I would pass it along as the
    events payload.

  4. 4 Posted by Quentin on 12 Jul, 2010 08:55 AM

    Quentin's Avatar

    Yes, but would you pass it all the way through?
    What bugs me is that there are a lot of steps between the first action (click to edit) and the last (update selected item)... Here's what it looks like:

    1. Select item+edit click
    2. Custom event (mapped to a command)
    3. Command execution
    4. Creation of an instance of a custom popup (mapped to a mediator)
    5. The mediator adds event listeners to the popup's UI
    6. User fills the edit (rename) form
    7. OK clicked (new event mapped to a command)
    8. Command executed to update the item.

    I don't really understand how my data (the VO and the new name) can travel all the way through and end up together in the last command...

    How do we pass the VO from the Command (step 3) to the popup instance (step 4)? Should I create a variable in it to receive that? That's what I'd do at first but that seems odd... Wouldn't that be redundant? Is there another way to do so?

  5. 5 Posted by Jason Dias on 12 Jul, 2010 09:37 AM

    Jason Dias's Avatar

    The short answer is Yes you would pass it all the way through. Here is a diagram outlining similar flow to what you have described. http://www.robotlegs.org/diagram/

    Here is an example

    1. In my view I would create an instance of this event and assign the item I want to install, then this event is dispatched to the mediator, and the mediator passes it along to the event bus.

      package com.example.events {

      public class UserEvent extends Event
          public static const INSTALL_ITEM:String = "UserEvent.INSTALL_ITEM";
          public static const ITEM_INSTALLED:String = "UserEvent.ITEM_INSTALLED";
          public var item:IInstallable;
          public function UserEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false )
              super( type, bubbles, cancelable );
          public override function clone():Event
              var myEvent:UserEvent = new UserEvent( type, bubbles, cancelable );
              myEvent.item = item;
              return myEvent;
          public override function toString():String
              return formatToString( "UserEvent", "type", "bubbles", "cancelable", "eventPhase" );


    2. I have a command named "InstallItemCommand" which has the UserEvent injected into it, this command also has my Service injected. I pass the item into the service, and the service processes that.

      package com.example.remote.requests {

      import com.jd.remoting.core.IRemotingService;
      import org.robotlegs.mvcs.Command;
      public class InstallItemRequestCommand extends Command
          public var event:UserEvent;
          public var service:IRemotingService;
          override public function execute():void
              service.request(new InstallItemRequest(event.item));


    3. Once the service has completed it's operation it creates another UserEvent instance, assigns the item that was installed to the event, and dispatches that into the event bus.

    4. If needed I would have another command mapped to the Installed event here to update the UserModel.

    5. My views mediator is also listening for the installed event, so once received it passes the installed item into the view to be displayed in the installed list.

    However it sounds like you might be trying to use RobotLegs MVCS implementation to do low level application logic. You might be better off putting the edit functionality into your view. Then you would only be sending the save through the event bus.

    It's really late here, and I may not be thinking clearly, if I am off please feel free to explain your situation further.

  6. 6 Posted by Quentin on 12 Jul, 2010 10:00 AM

    Quentin's Avatar

    You're right this is probably too low-level to be handled this way, it was looking to huge to be good (at least for this purpose)!

    I will try to have something simpler, I wanted to use all those events+commands+mediators that are new to me but I guess it's not really worth it here... At least I now understand how all this works!

    Thanks for all that, you made things a lot clearer.

  7. Quentin closed this discussion on 12 Jul, 2010 10:01 AM.

  8. Jason Dias re-opened this discussion on 12 Jul, 2010 10:04 AM

  9. 7 Posted by Jason Dias on 12 Jul, 2010 10:04 AM

    Jason Dias's Avatar

    No problem, Glad I could help.

  10. Quentin closed this discussion on 12 Jul, 2010 10:28 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac