capture the x and y position of a rectangle
Hi,
I'm working on a letting a user draw a rectangle to define a position on the stage. Te rectangle draws out ok. My problem is that I need to convert this dimensions and position of the rectangle in dynamic text. Plus, I need to make a way for the user to save these values into a text file.
Right now, I am able to capture the width and height, however, I can't seem to capture the x and y coordinates of the rectangle. I'd like to get the position of the top left corner if possible.
Here is what I have so far-
//Draws the final rectangle and logs the size and position
var hasRect: Boolean = false;
var rectHeight: Number;
var rectWidth: Number;
var rectXPos: Number;
var rectYPos: Number;
imprintHeightLabel.text = "Imprint Height: 0";
imprintWidthLabel.text = "Imprint Width: 0";
imprintXPosLabel.text = "Imprint X Position: 0";
imprintYPosLabel.text = "Imprint Y Position: 0";
function mUp(MouseEvent):void
{
mouseHolding = false;
if(hasRect == false)
{
myDrawing.graphics.lineStyle(2, 0xFF0000, 1);
myDrawing.graphics.beginFill(0xFF0000, 0.2);
myDrawing.graphics.drawRect(clickedX, clickedY, mouseX-clickedX, mouseY-clickedY);
myDrawing.graphics.endFill();
hasRect = true;
clearTemp();
rectHeight = myDrawing.height;
rectWidth = myDrawing.width;
rectYPos = myDrawing.y;
rectXPos = myDrawing.x;
if(hasRect == true)
{
imprintHeightLabel.text = "Imprint Height: " + rectHeight;
imprintWidthLabel.text = "Imprint Width: " + rectWidth;
imprintXPosLabel.text = "Imprint X Position: " + rectXPos;
imprintYPosLabel.text = "Imprint Y Position: " + rectYPos;
}
else
{
imprintHeightLabel.text = "Imprint Height: 0";
imprintWidthLabel.text = "Imprint Width: 0";
imprintXPosLabel.text = "Imprint X Position: 0";
imprintYPosLabel.text = "Imprint Y Position: 0";
}
}
}
