package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; public class Circle extends Sprite { private var cir:Sprite; private var drwRe:Sprite; public function Circle() { cir = new Sprite(); cir.graphics.beginFill(0x558899); cir.graphics.drawCircle(10,10,10); cir.graphics.endFill(); this.addChild(cir); stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoving); stage.addEventListener(Event.ENTER_FRAME, gameLoop); } private function createRe():void{ drwRe = new Sprite(); drwRe.graphics.beginFill(0xFF0000); drwRe.graphics.drawCircle(50,10,30); drwRe.graphics.endFill(); this.addChild(drwRe); } private function removeRe():void{ this.removeChild(drwRe); drwRe=null; } private function gameLoop(event:Event):void{ if(drwRe!=null){ if(drwRe.y>150){ removeRe(); return; } drwRe.y+=4; trace(drwRe.hitTestObject(cir)); this.setChildIndex(drwRe,this.numChildren-1); }else{ createRe(); } } private function onMouseMoving(event:MouseEvent):void{ cir.x = mouseX-10; cir.y = mouseY-10; // 鼠标碰到位图啦 //if(myBitmpData.hitTest(new Point(myBitmapData.x, myBitmapData.y), 255, new Point(mouseX, mouseY))) { //} if(drwRe!=null){ if(cir.hitTestObject(drwRe)){ this.setChildIndex(cir,this.numChildren-1); trace("tr"); } } } } }