# Event problem in AS3

**URL:** <https://forum.kirupa.com/t/event-problem-in-as3/268578>\
**Category:** flash\
**Created:** [August 15, 2008, 1:43pm UTC](https://forum.kirupa.com/t/event-problem-in-as3/268578 "2008-08-15T13:43:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro\_paulo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/pedro_paulo/32/2017_2.png) [@pedro\_paulo](https://forum.kirupa.com/u/pedro_paulo)\
**Post date:** [August 15, 2008, 1:43pm UTC](https://forum.kirupa.com/t/event-problem-in-as3/268578/1 "2008-08-15T13:43:04Z")

</div>

Hi, guys.

I´m with serious problem here. I´m studying AS3 for a few days and still cant do an Event system work properly.

After googling for a while I stopped here:

// Listener Class:

```auto

package{
 import flash.events.IEventDispatcher;
 import flash.events.Event;
 
 public class ListenerObject{
  
  private var label:String;
  
  public function ListenerObject(label:String){
   this.label = label;
  }
  
  public function addDispatcher(dispatcher:IEventDispatcher):void{
   dispatcher.addEventListener("testEvent", testEventHandler);
  }
  
  public function toString():String{
   return "[Listener "+label+"]";
  }
  
  private function testEventHandler(evt:Event):void{
   trace(evt.type+" dispatched from "+evt.target.toString()+" to "+this.toString());
  }
 }
}

```

// Dispatcher code:

```auto

package{
 import flash.events.EventDispatcher;
 import flash.events.Event;
 
 public class DispatcherObject extends EventDispatcher{
  
  private var label:String;
  
  public function DispatcherObject(label:String){
   this.label = label;
  }
  
  public override function toString():String{
   return "[Dispatcher "+label+"]";
  }
  
  public function dispatch():void{
   this.dispatchEvent(new Event("testEvent"));
  }
 }
}

```

// Main class code:

```auto

package {
 import flash.display.Sprite;
 public class EventsDemo extends Sprite{
  
  private var listener2:ListenerObject;
  public function EventsDemo(){
   
   var dispatcher1:DispatcherObject = new DispatcherObject("D1");
   
   var listener1:ListenerObject = new ListenerObject("L1");
   listener1.addDispatcher(dispatcher1);
   
   this.listener2= new ListenerObject("L2");
   listener2.addDispatcher(dispatcher1);
   
   this.addEventListener("testEvent", onList1);
   
   dispatcher1.dispatch();
   
   
  }
  
  public function onListL1():void {
   trace("onList L1");
  }
 }
}

```

But the problem is: At the “EventsDemo” class, I have the “Listener” class. And the function executede when the event is catched by the listener is the “testEventHandler”, wich is inside “Listener” class. What I want: Some object has the “Dispatcher”. When the “Dispatcher” instance fires an event broadcast, my “Listener” object catchs it and, based on Event type, calls a EventsDemo´s method.

In my particular case, I have a class wich loads an XML and parsing the data. The main class instantiate this XML class. What I want is when the XML have been parsed (some like “onDataDone” event) the main class is notified by a event broadcasting.

It used to be very simple in AS2, but with AS3 I´m going nuts!

Thanks for any help.

pp
