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

please help me, how can I find out the width of an object?

Community Beginner ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied


var page_body = document.getElementsByTagName("body")[0];

Hello.
Please tell me. )
I placed a square object on the canvas, and converted it into a symbol.
Gave him a name - chief
Now I'm writing code - 

 

page_body.style.overflow = "hidden";
page_body.style.position = "fixed";
var page_canvas = document.getElementsByTagName("canvas")[0];

var _this = this;

console.log("_this.chief.y - "+_this.chief.y);

console.log("_this.chief.x - "+_this.chief.x);

console.log("_this.chief.width - "+_this.chief.width);

 

console output - 

 

_this.chief.y - 351.05
_this.chief.x - 372.05
_this.chief.width - undefined

 

please help me, how can I find out the width of an object?

 

 

 

 

Views

565

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 , May 04, 2024 May 04, 2024

Hi.

 

If it is a CreateJS object created by Animate, you can use nominalBounds.width. If Animate didn't create this property for a CreateJS object, you can use, for many cases, getBounds() or getTransformedBounds() and then access the width if the result is not null.

 

Regards,

JC

Votes

Translate

Translate
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Hi.

 

If it is a CreateJS object created by Animate, you can use nominalBounds.width. If Animate didn't create this property for a CreateJS object, you can use, for many cases, getBounds() or getTransformedBounds() and then access the width if the result is not null.

 

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
Community Beginner ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Thank you

should I fix the code?

_this.chief.nominalBounds.width       

 

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

You're welcome.

 

What value do you get when you run _this.chief.nominalBounds.width?

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

and to use getBounds() and getTransformedBounds(), enable multiframe bounds in your publish settings.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

This is not needed.

 

Enabling Multiframes bounds creates a frameBounds property for each frame of a Movie Clip symbol that tels the developer the x, y, width and height of all the instances in that particular frame as whole.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

i don't recall either getbounds working unless it's enabled. are you saying that's no longer needed?

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

It's needed when the instance's bounding box changes due to a internal geometric change of its children. The nominalBounds property only contains information about the general bounding box of that instance when it's created at author time, but if we need to get the updated bounding box of a instance at runtime we need to use getBounds() and getTransformedBounds().

 

And getBounds() and getTransformedBounds() will only fail if we use it in objects that can't calculate their own bounds, like shapes. For this cases we should call setBounds first.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

are you saying a one frame movieclip can use getbounds without changing settings?

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Yep.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

this.a.getBounds() is undefined for movieclip a without changing settings.

 

(and you made me walk all the way into my house to my computer to test.)

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

It works because Animate creates CreateJS's display objects and CreateJS's display objects implement getBounds. The only exception, if setBounds is not used, is a shape.

 

I've worked in hundreds of HTML5 Canvas projects and have never turned Multiframe bounds on.

 

Multiframe bounds creates bounds for frames and not for individual display object instances. So it doesn't affect how getBounds works.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Your test is probably missing something.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

the only thing it's missing is multiframe bounds.

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 ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

in that link, i don't see anything that accounts for what i see.

 

kglad_0-1714916955779.png

 

 

enable frame bounds in the publish setting and both lines of code return the same.

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

The link explains what Multiframe bounds is.

image.png

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

Also, do you mind sending your test FLA?

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

no problem.  (and thank you.)

 

https://www.kglad.com/Files/forums/not_enabled.fla

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

Thanks for the file, k.

 

Just run your file without modifications and got this:

image.pngimage.png

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 ,
May 05, 2024 May 05, 2024

Copy link to clipboard

Copied

LATEST

i have no explanation.  this isn't anything new.  i've seen this since the first version of animate cc that allowed canvas files.

 

 

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