tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/275-robotlegs-application-communicating-with-external-elementsobjectsRobotlegs: Discussion 2018-10-18T16:35:17Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-09T22:42:27Z2010-09-09T22:42:27ZRobotlegs application communicating with external elements/objects<div><p>Hello iki_xx</p>
<p>That's the nice thing about using a plain old flash Event Dispatcher for communication - anything can listen in, just hand them your IEventDispatcher and they can listen for events.</p>
<p>To talk <em>to</em> your RL app you'd expose an API (interface) on your context view and talk through that. That interface would also be how you provide access to your event dispatcher.</p>
<p>In general though, I wouldn't recommend building a video player with Robotlegs, I'd build the player as a self-contained component. Frameworks like RL are used to wire components together into applications, not really to build those components - it's best to keep "framework/application" code out of your components.</p>
<p>You might use RL to build a video player, but only if that was the entire app - some kind of super advanced stand-alone video playing application.</p>
<p>I'm not saying that you can't use RL to build a component, but rather that using an "application framework" to build a component is often overkill. Of course, the line between "component" and "application" depends completely on the project at hand.</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-09T22:49:27Z2010-09-09T22:50:13ZRobotlegs application communicating with external elements/objects<div><p>To add a little to Shauns comment,</p>
<p>You might want to consider using OSMF (<a href="http://www.opensourcemediaframework.com/">http://www.opensourcemediaframework.com/</a>) to build your player, and then use Robotlegs to allow that player to communicate with the rest of your application.<br />
</p></div>Jason Diastag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-10T13:05:50Z2010-09-10T13:06:39ZRobotlegs application communicating with external elements/objects<div><p>@ Shaun</p>
<p>Thanks for the input about the EventDispatcher, just one more thing about that;<br />
If I use RL with AS3Signals, is the process the same? As I understand Signals also uses EventDispatcher internally?</p>
<p>About using RL to build a player , if I don't use RL , I would you just a simple MVC pattern, that would essentially function similar to the RL.<br />
Since RL has a small footprint , I see no reason not to do it with the RL.<br />
More questions:<br />
- If the player is built with RL , and I add it to display list , how do I later destroy the player that is built with RL?
I see that in the documentation there is a <code>shutdown()</code> method for the Context class<br />
But explanation is the same as for the <code>startup()</code> method.</p>
<p><code>public function shutdown():void
The Startup Hook
Override this in your Application context</code></p>
<ul>
<li><p>How does the shutdown work? Is that what I need to kill the RL framework?
Haven't seen it being used in the examples that I've looked at.</p></li>
<li><p>Also, what kind of cleaning do I have to do?
Kill the model?<br />
Kill the views?<br />
As I understand , mediators are automatically removed when views are removed from the display list , does that mean that all event mappings for that mediator are cleaned?<br />
</p></li>
<li>Is the <code>preRemove()</code> method the one I should use to clean what I need to manually clean in that mediator , just before it gets removed?</li>
</ul>
<p>@ Jason</p>
<p>I've looked at the OSMF , and it appears to me that you can only target FP10 + .<br />
Also, I've downloaded a couple of examples and they are all more than 300kb , that is to much for a video player.<br />
</p></div>iki_xxtag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-10T14:02:28Z2010-09-10T14:02:28ZRobotlegs application communicating with external elements/objects<div><p>hey!</p>
<p>"If I use RL with AS3Signals, is the process the same? As I understand Signals also uses EventDispatcher internally?"</p>
<p>No, Signals are not Event Dispatchers. If you are using Signals then you'd expose the Signals that you want access to through your API.</p>
<p>"Since RL has a small footprint , I see no reason not to do it with the RL."</p>
<p>RL does have a small footprint, but auto-mediation is not free - if you want to use RL to build the player, and you want to keep it really light, then I'd recommend turning auto-mediation off (<code>mediatorMap.enabled = false;</code>), and creating your mediators manually (<code>mediatorMap.createMediator(viewComponentInstance);</code>). However, if there will only be one instance off your player on screen at a time, then I wouldn't bother with any of that.</p>
<p>"If the player is built with RL , and I add it to display list , how do I later destroy the player that is built with RL?"</p>
<p>RL is an object-oriented design (no statics or Singletons) - all you need to do is drop all references to it and it will be free for Garbage Collection. In other words, simply remove the player from the stage and null your reference to it - when nothing is referencing the RL app the Flash Player will GC it.</p>
<p>If you need to perform any tear-down operations you can expose a method on your API that calls your context's shutdown() method. In that method you might dispatch an event that runs some tear-down commands and/or informs mediators. Once all your tear-down code has finished you might dispatch another event (to tell the outside app to remove the RL app from stage, for example).</p>
<p>"How does the shutdown work? Is that what I need to kill the RL framework?"</p>
<p>Shutdown() is a stub method (just like startup()) - you need to override it. It's up to you what goes in there. You might use the flow I described above, or you might simply run some code directly in the method itself.</p>
<p>"Also, what kind of cleaning do I have to do? Kill the model? Kill the views?"</p>
<p>That depends on your app. Often you can simply drop all references to the context, and it will free all the objects (as described above). Profile the application to see if any objects linger after removing the RL app from stage and nulling the reference.</p>
<p>"As I understand , mediators are automatically removed when views are removed from the display list , does that mean that all event mappings for that mediator are cleaned?"</p>
<p>Yes, if you used the mediators <code>eventMap</code> (each mediator gets its own) to perform the mappings then all listeners will be removed automatically when the mediator is removed from stage. Even if you don't use the mediators EventMap, cleanup is usually automatic (using weak references helps).</p>
<p>"Is the preRemove() method the one I should use to clean what I need to manually clean in that mediator , just before it gets removed?"</p>
<p>No, <code>preRemove()</code> and <code>preRegister()</code> are called by the mediatorMap, you'd want to override <code>onRemove()</code> (onRegister's partner).</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-10T19:25:47Z2010-09-10T19:38:07ZRobotlegs application communicating with external elements/objects<div><p>"<em> then I'd recommend turning auto-mediation off (mediatorMap.enabled = false;), and creating your mediators manually</em>"</p>
<p>questions:<br />
1. When the mediator map is disabled ,it is disabled for the entire application?<br />
2. When I call <code>mediatorMap.createMediator(mediatorToCreate);</code><br />
I'm creating the mediator at that time , so I need the view to already be on the stage, right?<br />
3. Later when I remove the view , I need to remove the mediator manually <code>removeMediator(mediatorToRemove);</code> ?</p></div>iki_xxtag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-13T15:29:06Z2010-09-13T15:29:06ZRobotlegs application communicating with external elements/objects<div><p><code>enabled</code> is a bad property name - what it actually does is enable/disable the stage listeners for the mediator map.</p>
<p>"When the mediator map is disabled ,it is disabled for the entire application?"</p>
<p>Disabling a mediator map will... disable it. There is usually only one mediator map in an RL context, in which case, yes, that will disable auto-mediation for the entire app. It's the stage listeners that are relatively expensive. But, as I said, if you only have one player, then it shouldn't make much difference. As with anything, profile your application to find bottlenecks. If you find that the mediator map is a bottleneck then turn auto-mediation off.</p>
<p>"When I call mediatorMap.createMediator(mediatorToCreate);
I'm creating the mediator at that time , so I need the view to already be on the stage, right?"</p>
<p>You don't pass it a mediatorToCreate, you pass it a view component to create a mediator for (one that you have already mapped). With manual mediation your view component doesn't have to be on stage as you are not relying on stage listeners to trigger creation.</p>
<p>"Later when I remove the view , I need to remove the mediator manually removeMediator(mediatorToRemove); ?"</p>
<p>Yes, if you go the manual mediation route then you will need to remove the mediators yourself.</p>
<p>Personally, I'd build the app with automatic mediation and then switch to manual mediation if performance is actually a problem.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/29071092010-09-13T17:49:45Z2010-09-13T17:49:45ZRobotlegs application communicating with external elements/objects<div><p>Thank you Shaun for taking time to answer all of my questions.</p></div>iki_xx