# dispatchEvent Help

**URL:** <https://forum.kirupa.com/t/dispatchevent-help/237705>\
**Category:** flash\
**Created:** [September 2, 2007, 10:58pm UTC](https://forum.kirupa.com/t/dispatchevent-help/237705 "2007-09-02T22:58:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DesignerScott](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/designerscott/32/2833_2.png) [@DesignerScott](https://forum.kirupa.com/u/DesignerScott)\
**Post date:** [September 2, 2007, 10:58pm UTC](https://forum.kirupa.com/t/dispatchevent-help/237705/1 "2007-09-02T22:58:10Z")

</div>

Hello again!  
I’m having some issues working with dispatchEvent()  
I need to have one class listen for the event, while the other dispatches it, but can’t seem to get it working. I’ve got dispatching down all within one class, but if I separate it out to a dispatcher class, and a listener class, it all falls apart. Here’s the code I’m working with:  
Dispatcher Class

```auto
package {
    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.IEventDispatcher;
    import CustomEvent;

    public class DispatcherClass extends Sprite {
        public var square:Sprite;
        private var square2:Sprite;
        private var dispatcher:IEventDispatcher;
        
        public function DispatcherClass():void {
            square = new Sprite();
            square.graphics.beginFill(0x123453);
            square.graphics.drawEllipse(50,50,25,25);
            square.graphics.endFill();
            addChild(square);
            square.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
        private function onMouseUp(evt:MouseEvent):void {
            dispatchEvent(new CustomEvent("custom"));
        }
        private function grow():void {
            this.x += 20;
        }
    }
}

```

Listener Class

```auto
package {

    import flash.display.Sprite
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.IEventDispatcher;
    import DispatcherClass;
    import CustomEvent;

    public class ListenerClass extends Sprite{
        
        public var dispatcher:DispatcherClass;
        
        public function ListenerClass():void {
            dispatcher= new DispatcherClass();
            addChild(dispatcher);
            addEventListener(CustomEvent.NEW_CUSTOM, dispatched);
        }
        private function dispatched(evt:CustomEvent):void {
            evt.target.grow();
        }        
    }
}

```

CustomEvent

```auto
package {
    
    import flash.events.Event;
    
    public class CustomEvent extends Event{
        
        public static const NEW_CUSTOM:String = "custom";
        private var command:String;
        
        public function CustomEvent(command:String){
            super(NEW_CUSTOM);
            this.command = command;
        }
    }
}

```

Gets no errors, but I don’t know why it won’t work either!  
Please take pity.
