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

Finding the Coordinates/ Location of an Element

Contributor ,
Feb 24, 2019 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!

Views

1.6K

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

correct answers 1 Correct answer

Community Expert , Feb 25, 2019 Feb 25, 2019

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

Votes

Translate

Translate
Community Expert ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

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

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
Contributor ,
Feb 25, 2019 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

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
LEGEND ,
Feb 25, 2019 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.

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
Contributor ,
Feb 25, 2019 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

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 ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

var instanceX=this.myInstanceName.x; // sim for 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
Contributor ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

LATEST

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

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
LEGEND ,
Feb 25, 2019 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.

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