2 Replies Latest reply on Apr 17, 2008 1:07 AM by Misenko

    determine component size after change

    Misenko
      Hi,

      I have a litle problem. I have Hbox with label component in it. When I change the label text, hbox size is automatically changed after all code is performed. But how to find out Hbox size, or label size (for example width) once after I change the text property of the label... For example...

      var myHbox:HBox = new HBox();
      var myLabel:Label = new Label();

      now the Hbox and lablel width and height is equal to zero. That's clear.

      Now I change:

      myLabel.text = "Some Long Text"
      myHbox.addChildren(myLabel)

      But now if I want determine actual size of label or hbox size, it is always zero.

      How can I determine the size at once, when I change the label text.

      thanks in advance
        • 1. Re: determine component size after change
          peterent Level 2
          Once you've made the changes to the child components, the Flex framework goes through an iteration of measuring the children and setting the HBox's new size.

          You've got a couple of choices. First, once you've set the size of the Label you can do: myHbox.validateNow() and then use myHbox.getExplicitOrMeasuredWidth() (there's a Height version, too) to get the HBox's new size. This doesn't allow the natural Flex framework process to flow, but it should do the trick.

          You could also try adding an event listener for the resize event on the HBox. If the changes to the child cause the HBox to have its size changed, it should trigger a resize event.

          I recommend doing that first.
          • 2. Re: determine component size after change
            Misenko Level 1
            Thank you very much, I've tried your first advice and it works great. But I'm sure the second one works either :)