1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Point; var circle:Sprite = new Sprite(); circle.graphics.beginFill( 0xFFCC00 ); circle.graphics.drawRect( 20 , 20 , 40 , 40 ); var cir2:Sprite= new Sprite(); cir2.graphics.beginFill( 0xFF00FF ); cir2.graphics.drawRect( 400 , 300 , 40 , 40 ); var tempX: int = 0 ; var tempY: int = 0 ; addChild(cir2); addChild(circle); circle.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown); function MouseDown(event:MouseEvent): void { circle.startDrag(); } circle.addEventListener(MouseEvent.MOUSE_UP, MouseReleased); function MouseReleased(event:MouseEvent): void { circle.stopDrag(); circle.hitTestObject(cir2); { tempX = circle.x + this .x; tempY = circle.y + this .y; //circle.x = cir2.x+ this.x; //circle.y = cir2.y+ this.y; cir2.x = -circle.x cir2.y = -circle.y } }; |