# Drawing rectangle x y position problem

**URL:** <https://forum.kirupa.com/t/drawing-rectangle-x-y-position-problem/288556>\
**Category:** flash\
**Created:** [May 18, 2009, 9:50am UTC](https://forum.kirupa.com/t/drawing-rectangle-x-y-position-problem/288556 "2009-05-18T09:50:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![probphp](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@probphp](https://forum.kirupa.com/u/probphp)\
**Post date:** [May 18, 2009, 9:50am UTC](https://forum.kirupa.com/t/drawing-rectangle-x-y-position-problem/288556/1 "2009-05-18T09:50:52Z")

</div>

Hello all,  
Plese look at my source.  
public function onMouseDownHandler(e:MouseEvent) {  
//trace(“mouse down clicked!”);  
if ( e.target is Stage )  
{  
GL.mouseIniX = mouseX;  
GL.mouseIniY = mouseY;  
switch(GL.isactive)  
{  
case “rect”:  
GL._draw\_obj\_id ++;  
// Create our new square and add some listeners to it to enabled dragging  
var mc:MovieClip = new MovieClip();  
mc.buttonMode = true;  
mc.name = "Rect_"+GL.\_draw\_obj\_id;  
mc.addEventListener(MouseEvent.MOUSE\_DOWN, startDraging);  
mc.addEventListener(MouseEvent.MOUSE\_UP, stopDraging);  
addChild( mc );  
GL.activeObject = mc;  
// Hold a reference so we can update its graphics using the drawing API  
GL.mcRef = mc;  
// DRAW!  
stage.addEventListener(Event.ENTER\_FRAME, square);  
break;  
case “txt”:  
trace(“text tool not yet!”);  
break;  
case “line”:  
trace(“line tool not yet!”);  
break;  
}  
}  
}

public function square(e:Event):void  
{  
GL.mcRef.graphics.clear();  
GL.mcRef.graphics.lineStyle(3, 0x000000, 1.0);  
GL.mcRef.graphics.beginFill(0xff9900, 1.0);  
GL.mcRef.graphics.drawRect(GL.mouseIniX, GL.mouseIniY, mouseX - GL.mouseIniX, mouseY - GL.mouseIniY);  
GL.mcRef.graphics.endFill();  
}

I am drawing a rectangle with the above code in as3 inside a area.  
Problem is that,  
when i try to acees the drawn rectangle x and y position it is showing 0,0.  
why is this?  
if i drag the drawn rectangle and try to access the x and y position then also it is calculating from the 0,0 position.  
first time when i draw the rectangle it is drawing well by dragging the mouse but why the x and y axis is 0,0;  
if i try to set the x and y position manually then when i try to draw by dragging , it is not drawing relative with the mouse.  
If any body have any idea please share it with me.  
I have spend lot of hours to do that but failed to solve it.  
Thanks in advance
