mediator doesn't catch component event

Anggie Bratadinata's Avatar

Anggie Bratadinata

24 Jan, 2011 03:38 AM

I'm having a problem with a listener to view component event in my mediator attached via eventMap.mapListener().
My CustomEvent is never caught.

Here are my codes:

Main class:
http://paste2.org/p/1208571

AppContext:
http://paste2.org/p/1208572

View component:
http://paste2.org/p/1208573

Mediator:
http://paste2.org/p/1208574

Customevent:
http://paste2.org/p/1208577

What I'm doing wrong?

Thanks a lot in advance.

  1. 1 Posted by Stray on 24 Jan, 2011 09:59 AM

    Stray's Avatar

    Hi there,

    there's nothing jumping out at me as being incorrect.

    I had wondered whether your meta data was getting dropped, or the framework wasn't all being included, but the fact that this works rules all of that out:

    view.addEventListener(ComponentEvent.CLICK, onComponentClick);

    Your event has clone overridden... so it's not that.

    Could you zip the whole lot for me? Including your project file, and then I can try to get it compiling here and see whether it works for me.

    Thanks,

    Stray

  2. 2 Posted by Anggie Bratadin... on 24 Jan, 2011 10:15 AM

    Anggie Bratadinata's Avatar

    Hi, Stray,

    Thanks for replying. I attached the project.

    Thanks again!

  3. Support Staff 3 Posted by Ondina D.F. on 24 Jan, 2011 11:34 AM

    Ondina D.F.'s Avatar

    Hi Anggie,

    Your example works on my end, meaning it traces:
    [object TodoListComponent]onClick

    [object ViewMediator]onComponentClick componentClick

    Nevertheless there are some things that I would do differently:

    Main.as

    private var context:AppContext; // keep a reference to your context instance

    public function Main():void
    {

    context = new AppContext(this);

    }

    instead of

    private function init(e:Event = null):void
    { removeEventListener(Event.ADDED_TO_STAGE, init);
    // entry point var context:AppContext = new AppContext(this);
    }

    from Common Problems (https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems) :

    The problem here is that the context is scoped as a local variable, and as such it will be free for Garbage Collection pretty much straight away. The context might function for a little while, but at some point in time it will be GC’d and cease to exist.

    ComponentEvent.as

    public static const COMPONENT_CLICK:String = "componentClick";// to prevent name collisions

    instead of

    public static const CLICK:String = "componentClick";

    ViewMediator.as

    private function onComponentClick(e:ComponentEvent):void

    so you can access the payload of your custom event , in case you need it in the Mediator

    instead of

    private function onComponentClick(e:Event):void

    TodoListComponent.as

    dispatchEvent(new ComponentEvent(ComponentEvent._COMPONENT_CLICK));

    instead of

    dispatchEvent(new ComponentEvent(ComponentEvent.CLICK));

    I’m sure Stray will give you more insight :)

    Ondina

  4. 4 Posted by Stray on 24 Jan, 2011 11:40 AM

    Stray's Avatar

    Well spotted Ondina - that's exactly what it is.

    The context isn't being held on to, and thus the mediator is disappearing after a couple of seconds, as it is only referenced in objects inside the context.

    Stray

  5. 5 Posted by Anggie Bratadin... on 24 Jan, 2011 01:31 PM

    Anggie Bratadinata's Avatar

    Ah, yes, moving context var out of the function fixed it.

    Thanks a lot guys!

  6. Stray closed this discussion on 11 Feb, 2011 11:16 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