Mediate Children

oscar's Avatar

oscar

11 Mar, 2010 09:48 PM

Hi,

I'm creating an app that has a Holder (that extends Canvas) View that accepts children added at run time. Each child can dispatch events that are been listened by their mediators.

Let's say the Holder has 3 children (added with addChild)
child1 (instance of class a)
child2 (instance of class b)
child3 (instance of class a)

If child3 dispatches an event, and Holder is listening to it, how do I know which child dispatched the event? I tried "currentTarget" in the vent, but it's a reference to the context.

Thanks in advance.

  1. 2 Posted by Stray on 11 Mar, 2010 09:52 PM

    Stray's Avatar

    Did you try .target rather than .currentTarget ?

    Not sure if it'll give you what you want but it sometimes does...

  2. 3 Posted by oscar on 11 Mar, 2010 09:55 PM

    oscar's Avatar

    Thanks for the fast response Stray.
    Yes, I tried target and has the same, a reference to the context.

    tks for checking.

  3. 4 Posted by Stray on 11 Mar, 2010 09:58 PM

    Stray's Avatar

    Ah - always worth a go but sometimes frustratingly unhelpful!

    To be honest if I need a reference to a specific view class (I have a multilayered collapsing menu that has this requirement) I tend to use an as3Signal and pass the view instance itself through the signal, or to create a custom event which requires the view instance as a parameter.

  4. Support Staff 5 Posted by Shaun Smith on 12 Mar, 2010 04:07 PM

    Shaun Smith's Avatar

    If target (or currentTarget) is a reference to the context, then it sounds like you are dispatching view events directly on the event bus (eventDispatcher), in which case the target is the event dispatcher itself (which just happens to be the context). The view components should be dispatching their own bubbling events - using themselves as the event dispatcher. That way, the target will be the view component that dispatched the event. Or am I misunderstanding what you're wanting to achieve?

  5. 6 Posted by Matan on 12 Mar, 2010 04:24 PM

    Matan's Avatar

    I agree with Shaun, I came to the same conclusion a while ago when starting with RL. After that so much more became clear. Shaun please confirm this:

    Each context has it's own eventDispatcher constructed at startup, this instance is then injected into all Actors of the shell (or anywhere you want it), thus listening and dispatching to/from the context's "eventBus" is available everywhere. So strong referencing your events with the class type becomes essential.

  6. Support Staff 7 Posted by Shaun Smith on 12 Mar, 2010 05:00 PM

    Shaun Smith's Avatar

    Confirmed!

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