tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/156-components-not-automatically-mediated-due-to-modular-loading-timingRobotlegs: Discussion 2018-10-18T16:35:12Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-11T10:20:07Z2010-05-11T10:20:07ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Hi Jim,</p>
<p>I'm using RL on a large modular project and the reason I haven't
switched up to the new modular solution is that it doesn't fit what
I need for the reason you're describing (and a few others).</p>
<p>I started with the previous Modular utility, added some extra
events and a ModuleStatusService class to handle the startup /
shutdown scenario - it's all much more asynchronous once your
modules are a decent size.</p>
<p>The old Modular utility is a bit more manual and doesn't use
child injectors, and does things in a slightly different order, but
it's working fine.</p>
<p>One of my modules is itself a module manager so that it can run
the show, but that could be deferred to the shell if preferred.</p>
<p>I can't share the code on here because it's a client project and
I haven't got time to strip out all the specifics, but all the
modular gubbins is pretty neutral, so if you drop me an email
(dailystraying at gmail dot com) then I'm happy to send over what
I've got.</p>
<p>Your solution will almost certainly need to be slightly
different but it might help you see the issues I've had to deal
with. My project is already out and running with beta users so I
don't think there's any modular issues we haven't dealt with
successfully.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-11T10:34:16Z2010-05-11T10:34:16ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Jim and Stray,</p>
<p>as Shaun, Joel and I have talked some about modular solutions
and as<br>
I'm also mulling over one that's slightly different from what
Joel<br>
has, I'd be very interested in knowing more about the
limitations<br>
Joel's approach has for you.</p>
<p>Ideally, we'd have a solution that doesn't cause timing
headaches and<br>
pretty much works - at least as an 80/20 solution - just out of
the<br>
box.</p>
<p>thanks,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-11T10:57:21Z2010-05-11T10:57:21ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Thanks Till,</p>
<p>I'll put something together - code examples and outline of the
problems - later today by email to you / Shaun / Joel.</p>
<p>I'd assumed I was in the 20 part of that pareto analysis, but
maybe some of my issues are wider.</p>
<p>Thanks!</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-11T11:03:01Z2010-05-11T11:03:01ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Thanks - that's appreciated.</p>
<p>Might well be that you're in the 20 part, yeah, but it doesn't
hurt to<br>
see whether we can go to 90/10 without bending over backwards
;)</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-11T14:49:09Z2010-05-11T14:49:09ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Mediating the contextView of the module's context will happen
regardless of timing, so that is a good place to start.</p>
<p>One approach that I haven't demonstrated (need to make a demo)
is using a module as a factory for visual components, as opposed to
being a visual component itself. In essence, it is created/loaded,
wired, registered, and then delivers mediated components which are
added to the stage by the shell. This approach requires modules to
mediate components "manually" as well, but is explicit and straight
forward.</p>
<p>I'm looking forward to your example Jim. It'll be fun to get
crackin on a solution. I think we are pretty close to something
generally useful. :></p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-12T02:28:48Z2010-05-12T02:28:48ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>So I thought about your problem a bit Jim. You have components
in the contextView, a Sprite or Flex Module I assume. Your module
is loaded and added to stage, at which point you provide it an
injector and start the context. At this point, all that should be
on the stage is an empty contextView. You map your mediators, map
the context view (which has a mediator created immediately) and
fire an event such as ContextEvent.STARTUP at that point. The
ContextViewMediator picks up that event and it fires the
createChildren() on contextView. Children are mediated
automagically, and all is happy with the word.</p>
<p>No?</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-12T03:17:01Z2010-05-12T03:17:03ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Ok here is the status of what I have done thus far. Stray
provide me with some code sample that are working correctly. After
looking them over, I realized that I could adapt Joel’s work
with what I have already. After a bit of refactoring, here is what
I came up with.<br>
I am loading components based upon Application, not Module (it
existed before I came). Anyway, I simply use a SWFLoader to load
the SWFs and listen for the Event.Complete as follows:<br></p>
<pre>
<code> var uri:String = content.contentUri;
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
loaderContext.securityDomain = SecurityDomain.currentDomain;
/* Create the swf loader and add it as a child to a canvas
* so that it will have a place to display on the display list
*/
loader = new SWFLoader();
loader.id = content.id;
loader.percentHeight = 100;
loader.percentWidth = 100;
loader.scaleContent = true;
loader.loaderContext = loaderContext;
loader.addEventListener(Event.COMPLETE, onLoadingComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onModuleLoadError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onModuleLoadError);
loader.load(uri);</code>
</pre>
<p>On the Event.COMPLETE fires, I dispatch another event and one of
my mediators picks it up. The real trick here is that I store a
reference to the module application in the event. Once I inject the
dependencies into the module , I add it as a child to a stub Canvas
in the order I want it in on my view stack. With auto-load set to
true in RL, the context is created before the components are added
to the stage and therefore all of my auto-magic component mediation
works. See the snippet below:<br></p>
<pre>
<code> Logger.debug("Setting parentInjector and starting the RL context for :" + moduleId);
// Inject dependencies into the module and initiate the context since autoload is set
var subApp:IModule = event.moduleApp;
injector.injectInto(subApp);
// Make sure the content fills the page
var subAppComponent:SubAppBase = SubAppBase(subApp);
subAppComponent.percentHeight = 100;
subAppComponent.percentWidth = 100;
/* Add to contentViewStack here based upon position
Simply add as a child to the stub canvas that already
exists for the module
*/
var index:int = _moduleArray.getItemIndex(swf);
var canvas:Canvas = Canvas(contentViewStack.getChildAt(index));
canvas.addChild(subAppComponent);</code>
</pre>
<p>I was ecstatic when this worked! Unfortunately, even though my
module content loads correctly, legends on my data visualization
components are oriented incorrectly and anytime I hover over a
tooltip, I get the message below. My euphoria quickly turned to
despair. It looks like the RL piece is working correctly, but
something is wrong on the AS3 side. It is always
something…</p>
<p>TypeError: Error <a href="/discussions/questions/1009" title=
"Discussion #1009">#1009</a>: Cannot access a property or method of
a null object reference.</p></div>Jim Boonetag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-19T02:14:01Z2010-05-19T02:14:05ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>Still no luck with this solution but it appears to be a
limitation of the SWFLoader so I took another tack.</p>
<p>I attempted to convert the Applications to Modules and use the
ModuleManager to load the swfs instead of SWFLoader. I had success
doing this in a simple project I put to together, but when I tried
to implement it in the main application, I am having troubles
getting the code that now inherits from Module and not Application
to compile. I keep getting the errors below. Computers are a PIA
sometimes.</p>
<p>[ERROR] <em>MySpendApp_mx_core_FlexModuleFactory.as:[13,14]
Interface method get preloadedRSLs in names pace
mx.core:IFlexModuleFactory not implemented by class</em>
MySpendApp_mx_core_FlexModuleFactory.publi<br>
c class <em>MySpendApp_mx_core_FlexModuleFactory<br>
[ERROR]</em> MySpendApp_mx_core_FlexModuleFactory.as:[13,14]
Interface method allowInsecureDomain in nam espace
mx.core:IFlexModuleFactory not implemented by class
<em>MySpendApp_mx_core_FlexModuleFactory.pub<br>
lic class</em> MySpendApp_mx_core_FlexModuleFactory<br>
[ERROR] <em>MySpendApp_mx_core_FlexModuleFactory.as:[13,14]
Interface method allowDomain in namespace m
x.core:IFlexModuleFactory not implemented by class</em>
MySpendApp_mx_core_FlexModuleFactory.public clas<br>
s _MySpendApp_mx_core_FlexModuleFactory</p></div>Jim Boonetag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-20T01:23:51Z2010-05-20T01:23:51ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><p>The above issue has been resolved. Apparently, if you get a hold
of a swc that was compiled with a newer SDK than you are using, AND
the APIs change, then you may run into a similar problem. Be
aware!</p></div>Jim Boonetag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-24T15:04:55Z2010-05-24T15:06:38ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><pre>
<code> Hello Joel ,
First of all , I have to say that I like Robotlegs even if I've just discovered it .
I have managed to use Stray 's robotlegs modular utility in Flash Builder . So when I have seen what you have posted , I have tried to use it in my application but with no success .
I can not manage to use the DoodadModule exemple in Flash Builder if I want to load it . I get the reference 'moduleInfo.factory.create() ' and put it in ShellContext , injector.injectInto(reference) .
If I cast the reference as DoodadModule , It works well .... but only without the view .I seems that in Flex 4 , you can not use addElement(ModuleClass) .
If I cast the reference as IModule , and addElement(reference as IVisualElement ) . It works well , moduleCommandMap work well , dispatchToModules work well ...but this time you can not use mediatorMap.mapView(DoodadModule, doodadModuleMediator ) . As the reference injected is an interface ( IModule) , DoodadModule is not recognize .
I have tried many things ( mediatorMap.createMediator() , injector.mapValue() , mediatorMap.mapView() with Class and Interface , Injector#createChild() with or without ApllicationDomain as param ... ) .I have read a lot here and on Robotlegs AS3 Google Groups . But I am always stuck at the same point . If you could explain to me what I did wrong , it would be nice and very helpful .I hope my english is understandable.
I thank you in advance .
Jean-François.</code>
</pre></div>Jefftag:robotlegs.tenderapp.com,2009-10-18:Comment/16519652010-05-27T08:54:57Z2010-05-27T08:55:02ZComponents Not Automatically Mediated Due to Modular Loading Timing <div><pre>
<code> Hello Joel ,</code>
</pre>
<p>It seems to work well now , I have to load moduleInfo with
(ApplicationDomain.currentDomain) as param .<br></p>
<p>Is it a good practice to put in the Context the reference as
IModule with injector.injectinto() .</p></div>Jeff