2 Replies Latest reply on Jun 10, 2014 4:19 PM by heavyboots

    HTML5 Canvas: Finding the height of a symbol

    LordMysterious Level 1

      Hey guys


      I'm probably missing something really obvious here.


      I have an image within a MovieClip in the library and I'm adding it to the stage using this code:


      var sym1 = new lib.symbolName();

      this.addChild(sym1 );


      However, I need to find the height of what I have just added to the stage, I have tried the obvious alert(sym1.height) but to no avail, I just keep getting 'undefined'.

      How would I go about doing this?



        • 1. Re: HTML5 Canvas: Finding the height of a symbol
          Nipun Asthana Adobe Employee

          If you're adding the object at runtime, use this:


          For named instances present on stage try this:



          1 person found this helpful
          • 2. Re: HTML5 Canvas: Finding the height of a symbol
            heavyboots Level 2

            Firstly, if you add it programmatically, it's up to you to name it on the stage too.


            Secondly, if you look closely at the getBounds function on createJS, you'll see that certain types don't automatically get a height and width. Depending on what's in your library symbol, you may need to convert it to a bitmap before bounds are automatically calculated.


            Here's some working code:



            var myStage = this;          // (I find 'this' very confusing so I try and define it at the stage level and talk to that going forward

            var sym1 = new lib.test();

            sym1.name = "sym1";     // This is key unless you only want to access your children by indexes (which may change?)

            myStage.addChild( sym1 );

            console.log( myStage.getChildByName("sym1").getBounds.height );

            1 person found this helpful