Skip to main content
Participant
May 4, 2024
Answered

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

  • May 4, 2024
  • 1 reply
  • 1398 views


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?

 

 

 

 

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 4, 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

    Participant
    May 4, 2024

    Thank you

    should I fix the code?

    _this.chief.nominalBounds.width       

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 4, 2024

    You're welcome.

     

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