# Custom event

**URL:** <https://forum.kirupa.com/t/custom-event/315100>\
**Category:** Uncategorized\
**Created:** [October 18, 2010, 1:26am UTC](https://forum.kirupa.com/t/custom-event/315100 "2010-10-18T01:26:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://forum.kirupa.com/u/jagguy)\
**Post date:** [October 18, 2010, 1:26am UTC](https://forum.kirupa.com/t/custom-event/315100/1 "2010-10-18T01:26:23Z")

</div>

I am learning how to do a custom event in AS3.  
I can do an event in a class but I dont know how to detect events in other classes.  
I want to detect in main.as an event reached in class player. eg a variable reached a value 4 in class payer and dispatches an event so main.as can detect it.

This doesnt give an error but my code doesnt output I can deect an event in main from classplayer.

//main  
myplayer=new ClassPlayer();  
myplayer.addEventListener(“image\_loaded”,imageLoadedHandler,false,0,true);  
myplayer.addEventListener (“watcher\_loaded”,watcher\_loadedHandler,false,0,true);  
addChild( myplayer);

// Handler methods  
private function watcher\_loadedHandler(e:Event):void {  
trace(“watcher in main”);  
}

//player  
var watcher:Watcher = new Watcher();  
…  
watcher.addEventListener(Watcher.VALUE\_REACHED, onValueReached, false, 0, true);  
…  
private function onValueReached(event:Event):void{  
trace(“watcher’s value is now at 4 in player”);  
dispatchEvent(new Event(“watcher\_loaded”));  
}

//watcher  
package {

```
  import flash.events.Event;
  import flash.events.EventDispatcher;

  public class Watcher extends EventDispatcher {
        
        public static const VALUE_REACHED:String = "valueReached";
        
         private var _value:Number = 0;
        
         public function Watcher():void { }
        
         public function get Value():Number {
              return _value;
        }
        
        public function set Value(num:Number):void {
              _value = num;
               if (_value == 4) {
                    var event:Event = new Event(Watcher.VALUE_REACHED);
                     dispatchEvent(event);
              }
               
        }
                    
  }

```

}
