Hi,
I have a class, which extends flash.display.Sprite.
package {
import flash.display.Sprite;
import flash.events.Event;
public class Circ extends Sprite {
public function Circ() {
init();
**this.addEventListener("MainEvent", onMainEvent);**
}
public function init():void {
var tmpCol:uint = Math.random()*16000000;
var tmpX:uint = Math.random()*400+50;
var tmpY:uint = Math.random()*200+50;
this.graphics.lineStyle(1);
this.graphics.beginFill(tmpCol);
this.graphics.drawCircle(tmpX, tmpY, 50);
this.graphics.endFill();
}
**public function onMainEvent(e:Event):void {
trace("MainEvent occurs!");
}**
}
}
These elements (Circ) will be added to the main timeline and should be listen
to the Event “MainEvent”.
I will dispatch an event (flash.events.Event) from root which should be
received by every Circ instance (children of root) on the stage.
/**
* first frame timeline
*/
import flash.events.Event;
for (var i:uint = 0; i < 5; i++) {
this.addChild(new Circ());
}
**this.dispatchEvent(new Event("MainEvent"));
**
I will that every Circ instance make the output “MainEvent occurs!”.
But this doesn’t work.
Could anyone help?