9 Replies Latest reply on Apr 13, 2009 2:22 PM by Brent Lamborn

    Trouble getting width on dynamic component (width is always 0)



      I'm a flex beginner and I've been struggling with getting a width on components I create in AS3 blocks. I have a TileList with a custom ItemRenderer called ImageRenderer. When a user clicks on one of my items, I'd like to pop it up on the screen along with some other components. I have this working:


      public function onClick(e:ListEvent):void{

      var i:Image = new Image();

      i.source = (e.itemRenderer as ImageRenderer).img.source;

      var h:VBox = new VBox();

      var t:TextArea = new TextArea();



      t.text = "Sample Text";

      h.x = 100;

      h.y = 100;


      trace(h.width, h.height, root.width, root.height);



      I get the Hbox to pop up on the screen, and the image displays, but the width and height I get for the Hbox is always zero. Can anyone tell me why this is so and how to fix it? I had another similiar problem doing something else I never resolved, so perhaps my understanding of how flex calculates width is wrong.