How do I create a mediator without Event.ADDED_TO_STAGE

lcfsoft's Avatar

lcfsoft

22 Feb, 2012 09:21 AM

I'm trying to use the robotlegs along with the nd2d (rendering engine/framework). The thing with it is that the Event.ADDED_TO_STAGE its elements dispatch are not being caught/processed/listened in the listeners mediatorMap creates.

What could be a work around for cases like this?

  1. 1 Posted by Abel de Beer on 22 Feb, 2012 09:50 AM

    Abel de Beer's Avatar

    Here are a few topics that revolve around a similar question:
    http://knowledge.robotlegs.org/discussions/questions/759-best-pract...
    http://knowledge.robotlegs.org/discussions/questions/806-is-robotle...
    http://knowledge.robotlegs.org/discussions/problems/330-away3d-plan...

    I'm not sure Shaun's answer in the first topic applies. If you still think you should be mediating your nd2d elements, let us know and we can think of possible solutions.

    [EDIT] I'll add this post as well, for more information: http://knowledge.robotlegs.org/discussions/solutions/9-mediate-non-...

  2. 2 Posted by lcfsoft on 22 Feb, 2012 01:35 PM

    lcfsoft's Avatar

    Hey Abel,

    Thanks for you reply!

    Yes, I'm pretty sure I need to mediate my nd2d elements. I have all the physics, model and remote services interactions taken care of and unit tested, now I need to add the View-Controller layer on top of that.

    Nd2d elements are the same thing (conceptually, from the MVC point of view) as Flash's built-in visual components. And they are certainly visual (i.e. not audio or the like as in your example).

    The problem with creating mediator manually is that many of those "sub-views" are created dynamically during the lifetime of the application. (Not to mention that the context is not the place to create views, really.)

    Thanks a lot for this topic: http://knowledge.robotlegs.org/discussions/problems/330-away3d-plan... - exactly the situation I'm having. There they refer to a custom mediatorMap (https://github.com/PaulTondeur/Robotlegs-Away3D-Extension/blob/mast...) implementation where they listen for special event instead:

    protected function addSceneListeners() : void {
        if (view3D) {
            view3D.scene.addEventListener(Scene3DEvent.ADDED_TO_SCENE, onViewAdded);
            view3D.scene.addEventListener(Scene3DEvent.REMOVED_FROM_SCENE, onViewRemoved);
        }
    }
    

    the event is Scene3DEvent which carries the target object as the payload (as an alternative to the default Robotlegs behavior based on bubbling and "target" property).
    I don't have a similar event in ND2D, sadly.

    Seems like it's the only way however and I'll have to extend both ND2D and Robotlegs, providing custom implementations. While it's relatively easy with Robotlegs (with interfaces and all that)... for ND2D I'm thinking there will be problems as I'll have to extend the root class Node2D. I'll have to look into that.

    Anyway, thanks a lot Abel: I think the third topic you mentioned answers my question. Well, sort of, as the answer is - there is no answer :)

    May be you have some other ideas that would not require me to go the hard way?

    Regards,
    Alex.

  3. 3 Posted by Abel de Beer on 23 Feb, 2012 10:49 AM

    Abel de Beer's Avatar

    To use automated Mediator creation and removal, Robotlegs listens for ADDED_TO_STAGE and REMOVED_FROM_STAGE events on its contextView. This contextView needs to be an instance of the abstract class DisplayObjectContainer, so that it can also be used to addChild() and removeChild(), among other things.

    This is what I gather from the ND2D code:
    World2D (subclasses Sprite): entry point for ND2D app
    World2D has a Scene2D (subclasses Node2D): used to add nodes to the scene
    Node2D (subclasses EventDispatcher): base 2D object, dispatches ADDED_TO_STAGE and REMOVED_FROM_STAGE events (https://github.com/nulldesign/nd2d/blob/master/src/de/nulldesign/nd...)

    So what you'd actually want is to set your Scene2D as the contextView, but since it doesn't extend DisplayObjectContainer, you won't be able to listen to these stage events with the default Robotlegs MediatorMap / Context implementation. What I'd suggest is to use a similar approach as mr. Paul Tondeur with this Away3D extension: create your own MediatorMap. It'll probably be easier to build on top of (extend) the default MediatorMap, since the normal Event classes are used. So, this does require diving deep into the Robotlegs code, but at least you'll have the Away3D example to guide you.

    Unfortunately I'm not able to provide you with more concrete examples, because I should invest my time in my work. ;)

    Good luck!

    PS: this is another situation where the new flexibility that Robotlegs 2 provides would come in handy, so maybe you'd want to look into the latest build!

  4. 4 Posted by lcfsoft on 23 Feb, 2012 12:03 PM

    lcfsoft's Avatar

    World2D is the contextView here, but yes, you got the point.
    Those ADDED_TO_STAGE events that Node2D dispatches won't bubble so it's not the same.

    Diving deep into Robotlegs doesn't scare me, extending ND2D does. May be it won't be necessary... I'll set some time aside this weekend to find out.

    this is another situation where the new flexibility that Robotlegs 2 provides would come in handy, so maybe you'd want to look into the latest build!

    I'm like 4 days into flash/as3 and 2 days into robotlegs :) Is the second version any stable? I don't need super stability for this particular project but nonetheless... I'll read more about it, found some tutorials already - thanks!

  5. 5 Posted by Abel de Beer on 24 Feb, 2012 11:31 AM

    Abel de Beer's Avatar

    I don't think you'd need to alter the ND2D code.

    Regarding RL2: I haven't played with it that much myself, but it definitely looks very promising! And the more people start using it now, the quicker bugs will get fixed. :)

    [EDIT] I'd like to point you to Shaun's comment in this thread again, just so you are aware of how you should look at combining Robotlegs with other frameworks that have their own renderer: http://knowledge.robotlegs.org/discussions/questions/759-best-pract...

  6. 6 Posted by Abel de Beer on 14 Mar, 2012 09:37 AM

    Abel de Beer's Avatar

    I case you're still interested, this looks like an interesting example (Starling Robotlegs plugin): https://github.com/s9tpepper/robotlegs-starling-plugin

  7. Ondina D.F. closed this discussion on 30 Mar, 2012 09:02 AM.

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