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?
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
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
Copy link to clipboard
Copied
Thank you
should I fix the code?
_this.chief.nominalBounds.width
Copy link to clipboard
Copied
You're welcome.
What value do you get when you run _this.chief.nominalBounds.width?
Copy link to clipboard
Copied
and to use getBounds() and getTransformedBounds(), enable multiframe bounds in your publish settings.
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.
Copy link to clipboard
Copied
i don't recall either getbounds working unless it's enabled. are you saying that's no longer needed?
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.
Copy link to clipboard
Copied
are you saying a one frame movieclip can use getbounds without changing settings?
Copy link to clipboard
Copied
Yep.
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.)
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.
Copy link to clipboard
Copied
Your test is probably missing something.
Copy link to clipboard
Copied
the only thing it's missing is multiframe bounds.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
in that link, i don't see anything that accounts for what i see.
enable frame bounds in the publish setting and both lines of code return the same.
Copy link to clipboard
Copied
The link explains what Multiframe bounds is.
Copy link to clipboard
Copied
Also, do you mind sending your test FLA?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for the file, k.
Just run your file without modifications and got this:
Copy link to clipboard
Copied
i have no explanation. this isn't anything new. i've seen this since the first version of animate cc that allowed canvas files.