Skip to main content
Participant
May 4, 2024 6:51 AM UTC
Answered

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


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 is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    May 4, 2024 11:09 AM UTC

    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

    20 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 4, 2024 11:09 AM UTC

    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

    Translate
    Participant
    May 4, 2024 11:16 AM UTC

    Thank you

    should I fix the code?

    _this.chief.nominalBounds.width       

     

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    May 4, 2024 12:30 PM UTC

    You're welcome.

     

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

    Translate