Highlighted

Finding the Coordinates/ Location of an Element

Contributor ,
Feb 24, 2019

Copy link to clipboard

Copied

Hi All,

I'm probably not using the correct search terms to find the answer in this forum:

I just need to find the x and y coordinates for an instance -relative to the stage.

(I'm publishing my FLA as a Canvas project using Animate CC.)

myCoordinate = this.myInstance.getBoundingClientRect();

alert (myCoordinate.top);

...Doesn't seem to work in my script window.

Thanks!

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

var instanceX=this.myInstanceName.x; // sim for y

Views

531

Likes

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

Finding the Coordinates/ Location of an Element

Contributor ,
Feb 24, 2019

Copy link to clipboard

Copied

Hi All,

I'm probably not using the correct search terms to find the answer in this forum:

I just need to find the x and y coordinates for an instance -relative to the stage.

(I'm publishing my FLA as a Canvas project using Animate CC.)

myCoordinate = this.myInstance.getBoundingClientRect();

alert (myCoordinate.top);

...Doesn't seem to work in my script window.

Thanks!

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

var instanceX=this.myInstanceName.x; // sim for y

Views

532

Likes

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
Feb 24, 2019 0
Adobe Community Professional ,
Feb 25, 2019

Copy link to clipboard

Copied

var rect:Rectangle=this.myInstance.getBounds(this);

Likes

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
Reply
Loading...
Feb 25, 2019 0
Contributor ,
Feb 25, 2019

Copy link to clipboard

Copied

Thanks Kglad.

If I use the 'var,' the FLA fails (a blank browser window results when publishing), so I put this in my Animate script window:

rect:Rectangle = this.myInstanceName.getBounds(this);

alert(rect);

...but no alert shows in the browser window upon publish.

Does that syntax not work with an Animate (Canvas) project?

I also tried:

myBounds = this.myInstanceName.getBounds(this);

alert(myBounds);

...but he alert shows "[Rectangle (x=0 y=0 width=42 height=42)]"  ---no x and y coordinates relative to the stage.

Am I doing something wrong? I just want to find the x and y coordinates (location) of the instance relative to the stage.

Thanks much

Likes

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
Reply
Loading...
Feb 25, 2019 0
Adobe Community Professional ,
Feb 25, 2019

Copy link to clipboard

Copied

He appears to be working in a Canvas document.

Paul, getBoundingClientRect() is browser DOM method. It does not exist in the Animate canvas API. If your object is nested within another clip, you'll probably need to use localToGlobal. But if it's sitting directly on the stage, you just access the clip's x and y properties.

Likes

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
Reply
Loading...
Feb 25, 2019 0
Contributor ,
Feb 25, 2019

Copy link to clipboard

Copied

Clay UUID wrote:

"Paul, getBoundingClientRect() is browser DOM method. It does not exist in the Animate canvas API. If your object is nested within another clip, you'll probably need to use localToGlobal. But if it's sitting directly on the stage, you just access the clip's x and y properties."

Yes it's just sitting on the stage. How can I access (find) the X and Y properties to find the coordinates?

Thanks

Likes

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
Reply
Loading...
Feb 25, 2019 0
Adobe Community Professional ,
Feb 25, 2019

Copy link to clipboard

Copied

var instanceX=this.myInstanceName.x; // sim for y

Likes

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
Reply
Loading...
Feb 25, 2019 1
Adobe Community Professional ,
Feb 25, 2019

Copy link to clipboard

Copied

paul_james123  wrote

Clay UUID wrote:

"Paul, getBoundingClientRect() is browser DOM method. It does not exist in the Animate canvas API. If your object is nested within another clip, you'll probably need to use localToGlobal. But if it's sitting directly on the stage, you just access the clip's x and y properties."

Yes it's just sitting on the stage. How can I access (find) the X and Y properties to find the coordinates?

Thanks

x is x. y is y. It's not complicated.

Likes

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
Reply
Loading...
Feb 25, 2019 0
Contributor ,
Feb 25, 2019

Copy link to clipboard

Copied

sheesh. Overthought that one. Thanks for your patience Clay UUID and Kglad.

Likes

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
Reply
Loading...
Feb 25, 2019 0