• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get nested X,Y Coordinates

Explorer ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

I'm coding an app where you draw shapes with the mouse. When the shape is complete it gets assigned the name "Room"+RoomNum. It then gets nested inside a MovieClip named MainStage. This all works fine but whenever a shape is added to MainStage the x,y coordinates of that shape are always 0,0 no matter where the shape is drawn. How do I get the actual coordinates relative to where it is on the MainStage MC?

My goal is to get those coorinates and place text in the centre of the shape.

Views

187

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

check the mouse x,y when the shape is being created.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Hi.

 

Are the shapes created only defined by drawing commands inside of MainStage or each shape gets it own container?

Also, is it AS3 or HTML5 Canvas?

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Hi, the shapes have their own container inside of MainStage. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Alright.

 

What's the code you're using to add the shapes to MainStage when the user finishes drawing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

I'm still getting to grips with coding in a conventional way so the following code is not stremlined.

This code is run after the shape is drawn. The shape and points are deleted and redrawn into a MovieClip, then added to MainStage. 

 

var TotalPoints = a;
MovieClip(root)["Room" + Room] = new MovieClip();
MovieClip(root)["Room" + Room].name = "Room" + Room;
MainStage.addChild(MovieClip(root)["Room" + Room]);
MovieClip(root)["Room" + Room].graphics.lineStyle(2, 0x000000, 1, true, LineScaleMode.NORMAL);
MovieClip(root)["Room" + Room].graphics.moveTo(MovieClip(root)["PointMC" + 1].x, MovieClip(root)["PointMC" + 1].y);
MovieClip(root)["Room" + Room].graphics.beginFill(0x66FF00, 0.2);

//Loop through Points and Lines
for (var i: uint = 1; i <= a; i++) {
var j = i + 1;
//Delete Points and Lines
MovieClip(root)["SolidLine" + i].graphics.clear();
//Redraw Room and add Points and Lines to MovieClip
if (i < TotalPoints) {
MovieClip(root)["Room" + Room].graphics.lineTo(MovieClip(root)["PointMC" + j].x, MovieClip(root)["PointMC" + j].y);
} else {
MovieClip(root)["Room" + Room].graphics.lineTo(MovieClip(root)["PointMC" + 1].x, MovieClip(root)["PointMC" + 1].y); //Close Path
}
}
MovieClip(root)["Room" + Room].graphics.endFill();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

and is the container position what you want?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

I'm after the x,y position of where the shape sits inside MainStage. I tried your earlier suggestion by checking the mouse x,y when drawn. I did this by getting the top left cordinates of the shape after drawn inside MainStage but before the shape was added to a Movieclip and re-added to Mainstage. It works but I thought there must be an easier way.

 

var SortX: Array;
	var SortY: Array;
	SortX = new Array;
	SortY = new Array;
	var d = 0;
	for (var b: int = 0; b < TotalPoints; b++) {
		d++;
		SortX[b] = MovieClip(root)["PointMC" + d].x;
		SortY[b] = MovieClip(root)["PointMC" + d].y;
	}
	SortX.sort(Array.NUMERIC);
	SortY.sort(Array.NUMERIC);
	ShapeRegX = SortX[0];
	ShapeRegY = SortY[0];

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

is the container's position what you want?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Yes, correct. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

then use its x,y

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

The shapes x,y is always 0,0 when added to the MainStage MovieClip, no matter where on the MainStage its added. I'm after the actual position of where it sits inside MainStage. Apologies if I'm not being clear. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

what is the x,y of container for example?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

LATEST

Thanks for the code.

 

What's happening is that moveTo and lineTo are creating the shapes in the cursor coordinates, but the parent of each shape remains at 0,0.

What I think you should be doing is to add each cointainer at the cursor position and then start using moveTo and lineTo from there.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines