4 Replies Latest reply on Nov 14, 2006 10:42 AM by __Voodoo__Child__

    Read the height of a percentHeight based object

      Hi, maybe my question is stupid but I would like to read the height of an object created by the code below and added by AddChild().

      Here what I do :

      for(Time=StartMinuteOfTheDay; Time<EndMinuteOfTheDay; Time+=PeriodOfTheDay) {
      var Can:Canvas = new Canvas();
      Can.width = DayBox.width;
      Can.percentHeight = 50;
      Can.id="Canvas";
      DayBox.addChild(Can);
      }

      Now I would like to access one of the objects created and read its height... But I don't know how to access one of the children !

      I try Canvas.height or Canvas[1].height and some other things, but without success !

      I hope someone could help me !
      Thanks a lot
        • 1. Access to a child adding by AddChild
          Level 1
          OK, I found a way to access my Child :

          var MyChild:UIComponent = UIComponent(DayBox.getChildAt(1)); // using import mx.core.UIComponent;

          But it seems that an object with a percentHeight has no height property...

          Does anyone know if it's possible to read the height property of a percent height based object ?
          • 2. Re: Read the height of a percentHeight based object
            __Voodoo__Child__ Level 1
            Try using the measuredHeight property to get a pixel value of the height.
            • 3. Re: Read the height of a percentHeight based object
              Level 1
              Thanks for your answer.

              I try measuredHeight property but the value is set to 0 and my object has a real height that is non zero.

              My Child is added by AS... May be that's why ???
              • 4. Read the height of a percentHeight based object
                __Voodoo__Child__ Level 1
                Hmm... a few questions
                What does the height property return?
                What is the DayBox's height property?
                At what point are you trying to read the height property? I ask this because, Flex will need to run its layout/positioning code before it can tell you what the rendered height will be.

                This works, but it is post render.
                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
                <mx:Script>
                <![CDATA[
                import mx.containers.Canvas;

                private function init():void
                {

                for(var i:int=0; i<7; i++)
                {
                trace('adding new canvas');
                var Can:Canvas = new Canvas();
                Can.width = DayBox.width;
                Can.percentHeight = 50;
                Can.width = 40;
                Can.setStyle("backgroundColor","#ffffcc");
                Can.id="Canvas";
                DayBox.addChild(Can);
                }
                }

                private function doitClick():void
                {
                mylabel.text=DayBox.getChildAt(1).height.toString();
                }
                ]]>
                </mx:Script>

                <mx:HBox id="DayBox" height="50%" borderStyle="solid" borderColor="#ff0080" left="20" right="20" top="40">
                </mx:HBox>
                <mx:Label id="mylabel" x="81" y="12" text="click button"/>
                <mx:Button click="doitClick()" x="20" y="10" label="Do it"/>
                </mx:Application>

                Note: I'm setting the width and background color, just so I can see them.