Hey folks I was wondering if someone can tell me my this code doesn’t work. It compiles with no errors, just the dispatchEvent call never fires
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
[SWF(width="800", height="600", backgroundColor="#FDFDFD", framerate="30")]
public class TestEvents extends Sprite
{
private var sp1:Sprite
private var sp2:Sprite
private var sp3:Sprite
private var mce:Event //MyCustomEvent
public function TestEvents()
{
mce=new Event("customEvent",true)
sp1=new Sprite()
sp1.graphics.beginFill(0xFF0000)
sp1.graphics.drawRect(0, 0, 100, 100)
sp1.graphics.endFill()
sp1.x=150
sp1.y=150
sp1.name="sp1"
addChild(sp1)
sp2=new Sprite()
sp2.graphics.beginFill(0x0000FF)
sp2.graphics.drawRect(0, 0, 100, 100)
sp2.graphics.endFill()
sp2.x=350
sp2.y=250
sp2.name="sp2"
addChild(sp2)
sp3=new Sprite()
sp3.graphics.beginFill(0x888888)
sp3.graphics.drawRect(0, 0, 50, 20)
sp3.graphics.endFill()
sp3.x=50
sp3.y=50
sp3.name="sp3"
addChild(sp3)
addEventListener("customEvent", handleEvent) // this hears customEvent
sp1.addEventListener("customEvent", notifyMe) //these never hear customEvent?
sp2.addEventListener("customEvent", notifyMe)
sp3.addEventListener(MouseEvent.CLICK, notifyOthers)
}
private function handleEvent(event:Event):void {
trace(event.type); // "customEvent"
}
private function notifyOthers(event:MouseEvent):void {
trace("notifyOthers")
dispatchEvent(mce)
}
private function notifyMe(event:Event):void {
trace("notifyMe: "+event.target.name)
}
}
}