Robotlegs application communicating with external elements/objects

iki_xx's Avatar

iki_xx

09 Sep, 2010 09:18 PM

I'm new to Robotlegs , and I have one question.
Lets say that I build a video player utilizing RL framework.
Next, I want to use that video player in a flash website, and I want the rest of the application/site to be able to receive events from the player, site is not built with RL framework
Scenario is this:

  • Video player is added to the display list , and initialized.
  • Other stuff/classes need to know when the video has started playing etc, so they can react appropriately ( black out the site,turn off the music , etc... ).
  • Also, external objects / classes need to manipulate the video player , they need to be able to call "play" , "stop" , "pause" ( inside the framework , model handles those methods)

I think that I need to register external objects to somehow listen to the events from the framework(player), and to expose those "play" "stop" "pause" methods (they are in the model) to the rest of the site.

What is the best way to approach this?

  1. Support Staff 1 Posted by Shaun Smith on 09 Sep, 2010 10:42 PM

    Shaun Smith's Avatar

    Hello iki_xx

    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.

    To talk to 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.

    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.

    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.

    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.

    Hope that helps!

  2. 2 Posted by Jason Dias on 09 Sep, 2010 10:49 PM

    Jason Dias's Avatar

    To add a little to Shauns comment,

    You might want to consider using OSMF (http://www.opensourcemediaframework.com/) to build your player, and then use Robotlegs to allow that player to communicate with the rest of your application.

  3. 3 Posted by iki_xx on 10 Sep, 2010 01:05 PM

    iki_xx's Avatar

    @ Shaun

    Thanks for the input about the EventDispatcher, just one more thing about that;
    If I use RL with AS3Signals, is the process the same? As I understand Signals also uses EventDispatcher internally?

    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.
    Since RL has a small footprint , I see no reason not to do it with the RL.
    More questions:
    - 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 shutdown() method for the Context class
    But explanation is the same as for the startup() method.

    public function shutdown():void The Startup Hook Override this in your Application context

    • 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.

    • Also, what kind of cleaning do I have to do? Kill the model?
      Kill the views?
      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?

    • 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?

    @ Jason

    I've looked at the OSMF , and it appears to me that you can only target FP10 + .
    Also, I've downloaded a couple of examples and they are all more than 300kb , that is to much for a video player.

  4. Support Staff 4 Posted by Shaun Smith on 10 Sep, 2010 02:02 PM

    Shaun Smith's Avatar

    hey!

    "If I use RL with AS3Signals, is the process the same? As I understand Signals also uses EventDispatcher internally?"

    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.

    "Since RL has a small footprint , I see no reason not to do it with the RL."

    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 (mediatorMap.enabled = false;), and creating your mediators manually (mediatorMap.createMediator(viewComponentInstance);). 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.

    "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?"

    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.

    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).

    "How does the shutdown work? Is that what I need to kill the RL framework?"

    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.

    "Also, what kind of cleaning do I have to do? Kill the model? Kill the views?"

    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.

    "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?"

    Yes, if you used the mediators eventMap (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).

    "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?"

    No, preRemove() and preRegister() are called by the mediatorMap, you'd want to override onRemove() (onRegister's partner).

    Hope that helps!

  5. 5 Posted by iki_xx on 10 Sep, 2010 07:25 PM

    iki_xx's Avatar

    " then I'd recommend turning auto-mediation off (mediatorMap.enabled = false;), and creating your mediators manually"

    questions:
    1. When the mediator map is disabled ,it is disabled for the entire application?
    2. 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?
    3. Later when I remove the view , I need to remove the mediator manually removeMediator(mediatorToRemove); ?

  6. Support Staff 6 Posted by Shaun Smith on 13 Sep, 2010 03:29 PM

    Shaun Smith's Avatar

    enabled is a bad property name - what it actually does is enable/disable the stage listeners for the mediator map.

    "When the mediator map is disabled ,it is disabled for the entire application?"

    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.

    "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?"

    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.

    "Later when I remove the view , I need to remove the mediator manually removeMediator(mediatorToRemove); ?"

    Yes, if you go the manual mediation route then you will need to remove the mediators yourself.

    Personally, I'd build the app with automatic mediation and then switch to manual mediation if performance is actually a problem.

  7. 7 Posted by iki_xx on 13 Sep, 2010 05:49 PM

    iki_xx's Avatar

    Thank you Shaun for taking time to answer all of my questions.

  8. iki_xx closed this discussion on 13 Sep, 2010 05:50 PM.

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