Вот 3 мои класса.
RandCircle.as
![](images/russian/style3/buttons/collapse_thead_collapsed.gif)
Код AS3:
package{
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
public class RandCircle extends Sprite{
private var timer:Timer=new Timer(100);
const REMOVE_ME="REMOVE_ME";
public function RandCircle(){
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
private function onTimer(e:TimerEvent):void{
var circle:Circle = new Circle();
circle.addEventListener(MyEvent.REMOVE_ME,onRemoveChild);
addChild(circle);
trace(this.numChildren);
}
private function onRemoveChild(e:MyEvent):void {
removeChild(Circle(e.target));
}
}
}
Circle.as
![](images/russian/style3/buttons/collapse_thead_collapsed.gif)
Код AS3:
package{
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.*;
public class Circle extends Sprite{
const REMOVE_ME="REMOVE_ME";
private var timer:Timer=new Timer(150,0);
private var randX:Number=Math.random()*550;
private var randY:Number=Math.random()*400;
private var randR:Number=Math.random()*75+20;
public function Circle(){
drawThis();
timer.addEventListener(TimerEvent.TIMER,onTimer);
timer.start();
}
private function drawThis():void{
graphics.lineStyle(1,0x000000,1);
graphics.beginFill(0xFFCC99,1);
graphics.drawCircle(randX,randY,randR);
}
private function onTimer(e:TimerEvent):void{
this.alpha -= 0.1;
dispatchEvent(REMOVE_ME);
}
}
}
MyEvent.as
![](images/russian/style3/buttons/collapse_thead_collapsed.gif)
Код AS3:
package {
import flash.events.Event;
public class MyEvent extends Event{
public static var REMOVE_ME:String="REMOVE_ME";
public function MyEvent(type:String) {
super(type);
}
public override function clone():Event {
return new MyEvent(type);
}
}
}
Возникает одна лишь ошибка:
TypeError: Error #1034: Ошибка типа Coercion: невозможно преобразовать "REMOVE_ME" в flash.events.Event.