Modules in a Popup (or should I say Popup Modules?)
I have reviewed the example projects located here: 20-links-to-robotlegs-v2-articles-examples-demos-utilities-and-tutorials and it's been extremely helpful in getting familiar with RL2.
I'm trying to load a module which will have it's own context/config/mediators/etc and present it in a popup. I haven't found any examples that deal with this specifically. There's discussions about modules, inter-module communication, and popups, but most are outdated and I've had a hard time wrapping my head around exactly how this should be done.
I had this working in RL1, so I'm certain it can be done (and
probably much easier) in RL2
Here's the relevant parts of my old application's command
class.
override public function execute():void
{
//create the checkout module
info = ModuleManager.getModule("com/mydomain/app/modules/checkout/CheckoutModule.swf");
info.addEventListener(ModuleEvent.READY, onCheckoutModuleLoaded);
info.addEventListener(ModuleEvent.ERROR, onCheckoutModuleError);
info.load(ApplicationDomain.currentDomain, null, null, Application(contextView).moduleFactory);
}
private function onCheckoutModuleLoaded(event:ModuleEvent):void
{
var popup:IFlexDisplayObject = info.factory.create() as IFlexDisplayObject;
info.removeEventListener(ModuleEvent.READY, onCheckoutModuleLoaded);
info.removeEventListener(ModuleEvent.ERROR, onCheckoutModuleError);
info = null;
injector.injectInto(popup);
PopUpManager.addPopUp(popup, contextView, true);
PopUpManager.centerPopUp(popup);
}
Any help here would be MUCH appreciated! Hopefully I'm not the only one that wants to have mediated modules as a popup. – Am I?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | 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
Support Staff 1 Posted by Ondina D.F. on Jun 20, 2013 @ 08:11 AM
Hello,
No, you’re not the only one wanting that :)
I’m also interested in Modules, Popups, Windows &Co.
I was able to load Modules in a popup window and let them communicate with other Modules and/or the shell. I’m using Flex.
PopUpModuleView is then loading the Module.
In rl2 you’ll need the viewManager to manage the popup and the ModularConnector for intermodular communication.
http://knowledge.robotlegs.org/discussions/robotlegs-2/553-viewmana...
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
I’ll tell you more about this later on today, if you want.
Ondina
Support Staff 2 Posted by Ondina D.F. on Jun 20, 2013 @ 02:24 PM
Hey Beau,
I've attached an example of a Module loaded inside a popup window. Please see this post:
http://knowledge.robotlegs.org/discussions/robotlegs-2/3327-go-modu...
Let me know, if it helped.
Ondina
3 Posted by beaubrewer on Jun 20, 2013 @ 11:14 PM
Ondina,
It's been said many times before but I still have to say... YOU ROCK! Your example and references are a big help!
Your example raised a few questions for me.
First, I see you initialize the context from within an onCreationComplete handler vs. in MXML within a tag. Is there a benefit to doing it this way vs. the other?
Second, have you seen any memory or performance issues doing this on a larger scale? Any insight on unloading the modules effectively? I know this has been discussed and there are a number of discussions about the StyleManager holding references, etc.... but just wanted to see if there is a final BEST PRACTICE approach to this.
Support Staff 4 Posted by Ondina D.F. on Jun 21, 2013 @ 09:14 AM
Wow, thank you. You made me blush :) Who doesn't want to hear nice things about themselves once in awhile?
It’s just a matter of preferences. Having the context initialization in actionscript makes it easy to use the same code in a pure as3 project as well.
Do you mean because of the way the context was initialized? If so, I haven’t encountered any issues until now, not even in large scale projects.
I’ve became quite obsessed with GC &Co over the years ;)
I don’t know of any ultimate best practices; I can only share my experience and lots of links to articles on gc/ memory/performance. If you want, I can give you the links, but I’m sure you’ve already read a lot on the subject.
Some general rules that I follow:
before removing the View from the stage, remove all event listeners;
if you use bindings for properties, data providers etc, make sure they don’t keep the view alive in a way or another
same with dictionaries, styles (as you know), itemRenderers
using a profiler (I’m using FlashBuilder’s Profiler) helps you identify the objects holding a reference to a class;
make sure the View isn’t referenced elsewhere in your app, for example in a Model’s dictionary
if you add a View like this:
because someView is declared outside the function, there will be a reference to it, thus it won’t get gc-ed when you remove someView from stage, w/o setting it to null. So, the scope of variables is also important.
That’s all that comes to my mind right now. I’ll make sure to write comments regarding gc in my example and a readme on github. If you want to contribute, you can go through the discussions on this forum and gather the tips and suggestions concerning gc+memory, summarize them in here, and I’ll add them to the readme (mentioning your contribution).
Of course, only if your time permits!!
Also, look at Hans’ tips on gc:
https://github.com/dotdotcommadot/ModularRL
Thanks again for your kind words:)
Ondina
Support Staff 5 Posted by Ondina D.F. on Jun 27, 2013 @ 07:58 AM
Hey Beau, you can re-open this discussion, if need be.
Ondina D.F. closed this discussion on Jun 27, 2013 @ 07:58 AM.