Mediator doesn't work when dispatching existing event

Hez's Avatar


25 Jun, 2010 03:28 AM


MyEvent is mapped to a command.

MyEvent is dispatched when the user clicked on a button.

So the following is my mediator:

public class MyViewMediator extends Mediator
    public var view:MyView;

    override public function onRegister():void
        eventMap.mapListener(view, MyEvent.CALCULATE, handleCalculate);

    private function handleCalculate(event:MyEvent):void
        // this will not work by dispatching the existing event
        // dispatch(event); 

        // this is working!
        dispatch(new MyEvent(MyEvent.CALCULATE));

I'm wondering why it doesn't work if we dispatching the existing event as commented in the code?

  1. 1 Posted by Hez on 25 Jun, 2010 06:52 AM

    Hez's Avatar

    OK, the problem is resolved by adding the following clone() in MyEvent.

    public class MyEvent extends Event
        override public function clone():Event
            return new MyEvent(this.type);

    So I think it is a must for Robotlegs application to provide a clone() in every custom event?

  2. Support Staff 2 Posted by Joel Hooks on 25 Jun, 2010 07:17 AM

    Joel Hooks's Avatar

    It is best practice with ANY custom events, irrespective of framework, to override the clone() method. Events cannot be redispatched or bubbled without doing so.

  3. Joel Hooks closed this discussion on 25 Jun, 2010 07:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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