package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite {
public function Main():void {
var a:Sprite=new Sprite();
drawSprite(a,200,200,0x00ff00,0,0);
a.name="外层";
var b:Sprite=new Sprite();
drawSprite(b,100,100,0xff0000,50,50);
b.name="中层";
var c:Sprite=new Sprite();
drawSprite(c,50,50,0x0000ff,75,75);
c.name="内层";
addChild(a);
a.addChild(b);
b.addChild(c);
a.addEventListener(MouseEvent.CLICK,look);
b.addEventListener(MouseEvent.CLICK,look);
c.addEventListener(MouseEvent.CLICK,look);
}
private function look(evt:MouseEvent):void {
trace("发生事件的对象:"+evt.target.name);
trace("正在侦听事件的目标:"+evt.currentTarget.name);
trace("当前帧听的阶段:"+evt.eventPhase);
trace("================");
}
private function drawSprite(obj:Sprite,w:uint,h:uint,color:uint,X:uint,Y:uint) {
obj.graphics.beginFill(color);
obj.graphics.drawRect(X,Y,w,h);
obj.graphics.endFill();
}
}
}