6 Replies Latest reply on Feb 7, 2009 12:50 PM by Clifford Meece

    When is a component height set?

    Clifford Meece
      I'm trying to dynamically create controls and place them at my current mouse position. The components I'm generating are custom components extended from Hbox. The problem is that the height attribute seems to be set much too late in the process, so I can't seem to place the controls exactly where I want them.

      Is there a way to force a newly created Hbox derivative to figure out its height so I can add it to my canvas at the correct location?
        • 1. Re: When is a component height set?
          Level 7

          "Clifford Meece" <webforumsuser@macromedia.com> wrote in message
          news:gmj34d$rba$1@forums.macromedia.com...
          > I'm trying to dynamically create controls and place them at my current
          > mouse
          > position. The components I'm generating are custom components extended
          > from
          > Hbox. The problem is that the height attribute seems to be set much too
          > late
          > in the process, so I can't seem to place the controls exactly where I want
          > them.
          >
          > Is there a way to force a newly created Hbox derivative to figure out its
          > height so I can add it to my canvas at the correct location?
          >

          SetActualSize.


          • 2. Re: When is a component height set?
            Clifford Meece Level 1
            SetActualSize appears to take a height and width to SET the size, but if I knew the height I wouldn't need it, because I could just place my component via move(mouseX,mouseY-height_that_I_already_know)

            What I am looking for is a way to tell Hbox to size ITSELF, ie size itself based on it's children, so that I can query it for it's height Then I could say:

            newHbox = new CustomHBox; //HBox has its own children
            addChild(newHbox)
            newHBox.move(mouseX,mouseY-newHBox.height)

            In other words, at some point in the process, HBox DOES know it's height, but apparently only after it is actually displayed. So how do I place something on a canvas in a predefined location, accounting for it's height, before it is displayed?
            • 3. Re: When is a component height set?
              Clifford Meece Level 1
              ValidateNow() is the function I needed. Caveat: it was necessary to run this in the parent container. Running newHbox.validateNow() did nothing.
              • 4. Re: When is a component height set?
                Level 7

                "Clifford Meece" <webforumsuser@macromedia.com> wrote in message
                news:gmk9cq$bts$1@forums.macromedia.com...
                > SetActualSize appears to take a height and width to SET the size, but if I
                > knew
                > the height I wouldn't need it, because I could just place my component via
                > move(mouseX,mouseY-height_that_I_already_know)
                >
                > What I am looking for is a way to tell Hbox to size ITSELF, ie size itself
                > based on it's children, so that I can query it for it's height Then I
                > could
                > say:
                >
                > newHbox = new CustomHBox; //HBox has its own children
                > addChild(newHbox)
                > newHBox.move(mouseX,mouseY-newHBox.height)
                >
                > In other words, at some point in the process, HBox DOES know it's height,
                > but
                > apparently only after it is actually displayed. So how do I place
                > something on
                > a canvas in a predefined location, accounting for it's height, before it
                > is
                > displayed?


                Try:
                newHBox.setActualSize(newHBox.measuredWidth, newHBox.measuredHeight)

                I'm pretty sure that the documentation for setActualSize has very similar
                code, so I'm surprised you're not already using it. If that doesn't work,
                come back and try asking the reverse of what you're asking (think
                event-based rather than procedurally).

                HTH;

                Amy


                • 5. Re: When is a component height set?
                  Level 7

                  "Clifford Meece" <webforumsuser@macromedia.com> wrote in message
                  news:gmkaja$da0$1@forums.macromedia.com...
                  > ValidateNow() is the function I needed. Caveat: it was necessary to run
                  > this in the parent container. Running newHbox.validateNow() did nothing.

                  Shame you didn't take this as an opportunity to learn about the invalidation
                  cycle and how it works. Still, if you can get it to work without
                  learning... :-)


                  • 6. Re: When is a component height set?
                    Clifford Meece Level 1
                    wow, did you wake up on the wrong side of the bed or something? Your solution didn't work; get over it. I was actually following the advice in the livedocs that says that you should use validateNow to force layout for situations where you need to to access layout parameters before everything is visible.

                    I didn't see anything in the setActualSize docs that 'had very similar code' like you're suggesting, and the first few hits on google for setActualSize were people who have found that setActualSize actually doesn't usually set Actual Size.

                    Before your advice, I had already tried measuredWidth and measuredHeight and they were likewise zero. Maybe you need to learn about the validation cycle and when measurements get made?

                    oh, but shame on me for not wanting to learn.