package { import flash.display.Shape; import flash.display.Sprite; import flash.events.MouseEvent; import flash.text.TextField; [SWF(width="1000", height="600", backgroundColor="#ffffff", frameRate="30")] public class vis_demo2 extends Sprite { static const GRID_SIZE:int = 20; var posField:TextField = new TextField(); public function vis_demo2() { drawGrid(); addChild(posField); trace("bounds: " + getBounds(this)); addChild(getDot()); } private function displayPosition(x:int, y:int):void { posField.text = "X: " + x + ", Y: " + y; } private function getDot():Sprite { var board:Sprite = new Sprite(); var myPoint:Sprite = new Sprite(); stage.addChild(board); board.addChild(myPoint); myPoint.graphics.lineStyle(1,0); myPoint.graphics.beginFill(0); myPoint.graphics.drawCircle(0,0,20); myPoint.graphics.endFill(); myPoint.x = 50; myPoint.y = 50; // Register mouse event listeners. myPoint.addEventListener(MouseEvent.MOUSE_DOWN, function startMove(evt:MouseEvent):void { myPoint.startDrag(); // Change transparency on mouse down myPoint.alpha = .5; }); myPoint.addEventListener(MouseEvent.MOUSE_UP, function stopMove(e:MouseEvent):void { myPoint.stopDrag(); // Change transparency on mouse up myPoint.alpha = 1; displayPosition(myPoint.x, myPoint.y); }); // Return reference to dot container. return board; } private function drawGrid():void { var container:Shape = new Shape(); container.graphics.lineStyle(1, 1, .2); trace("width: " + width + ", height: " + this.height); // Vertical lines. for (var x:int = 0; x < 1200; x += GRID_SIZE) { container.graphics.moveTo(x, 0); container.graphics.lineTo(x, 1200); } // Horizontal lines. for (var y:int = 0; y < 1200; y += GRID_SIZE) { container.graphics.moveTo(0, y); container.graphics.lineTo(1200, y); } addChild(container); } } }