10 Replies Latest reply on Aug 27, 2007 12:50 PM by levancho

    TextArea.textWidth & TextArea.textHeight

    WandiZhang Level 1
      Here is the Flex code :

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      <mx:Script>
      <![CDATA[

      private function _check():void
      {
      test.validateNow();
      trace("checking = " + test.textHeight + " " + test.textWidth);
      // test.height = test.textHeight;
      }
      ]]>
      </mx:Script>
      <mx:TextArea
      id="test"
      width="600" height="100"
      wordWrap="true"
      text="iofjw oiajwe ofij oawijefawoigjeruh awuiohefiaw uhefioj ioawej oaiwje foijawoegjao oaiwjf eoahegiu awiuh iawhefhawihef iawuhef iauwhef iawefh iruhg uerh greg oawjeifioawj efoiawje foawrhgi awerghiawheiua wfiehawefiuhawie fawie fawi f aw efawfhawei fawihfe iawuhfi aweiawiue iawhfeiuaw fiawehf iawehf "
      creationComplete="_check()">
      </mx:TextArea>
      <mx:Button x="233" y="206" label="Button" click="_check()"/>
      </mx:Application>

      What I am trying to do is to find out about textWidth and textHeight of the textArea.

      It gives me 293 for the height and 100 for the width, which is completely wrong!

      What did I do wrong ?

      W.
        • 1. Re: TextArea.textWidth &amp; TextArea.textHeight
          AnthonyPetty Level 1
          I think you might be confusing textHeight with Height and textWidth with Width. Try retrieving these properties instead.
          • 2. Re: TextArea.textWidth &amp; TextArea.textHeight
            WandiZhang Level 1
            Nope Anthony, I am not trying to retrive the Height and the Width. If you look at my code, those values are explicitly set.

            I need to get textHeight and textWidth in order to dynamically change the height and the width of the TextArea, so it is no use for me to retrive those values
            • 3. Re: TextArea.textWidth &amp; TextArea.textHeight
              WandiZhang Level 1
              Maybe there is one sentense in my original post that is causing the confusion...

              "It gives me 293 for the height and 100 for the width, which is completely wrong!"

              should be

              "It gives me 293 for the textHeight and 100 for the textWidth, which is completely wrong!"

              my bad.



              • 4. Re: TextArea.textWidth &amp; TextArea.textHeight
                WandiZhang Level 1
                It seems that I am not the only one with this problem:

                http://www.nabble.com/Flex-TextArea-Autosize-issues-tf3674663.html#a10267989

                Any idea anyone? Or its just a bug in Flex?

                W.
                • 5. TextArea.textWidth &amp; TextArea.textHeight
                  levancho Level 3
                  actualy according to SDK it should work as you have it (I think)

                  ...edited.
                  • 6. Re: TextArea.textWidth &amp; TextArea.textHeight
                    WandiZhang Level 1
                    Yes, but unfortunately, when you run the code I put in my first message, it does not work the way it should.

                    So Flex is simply buggy ? I mean, this is no serious !

                    W
                    • 7. Re: TextArea.textWidth &amp; TextArea.textHeight
                      levancho Level 3
                      quote:

                      Originally posted by: WandiZhang
                      So Flex is simply buggy ? I mean, this is no serious !

                      W

                      in reality there is no bug free software, even life itself is not bug free,
                      question is what is the trade off, I think what Flex can offer overweights Number of bugs it has ,
                      plus Flex is almost Open source so everyone will have chance to contribute bug reports/fixes to make it better and better over time .
                      • 8. TextArea.textWidth &amp; TextArea.textHeight
                        levancho Level 3
                        actualy I just run your code and there is *almost* nothing wrong with it, it works as it supposed to :


                        from Flex 2 SDK:

                        textHeight property

                        textHeight:Number [read-only]
                        The height of the text.

                        The value of the textHeight property is correct only after the component has been validated. If you set text and then immediately ask for the textHeight, you might receive an incorrect value. You should wait for the component to validate or call the validateNow() method before you get the value. This behavior differs from that of the flash.text.TextField control, which updates the value immediately.


                        you have to validate before able to use the textHeight, . when you click on button it does call validateNow() so values change accordingly to size of the text's *pseudo container(invisible) *
                        the only thing that is little strange is that if you clear text area it reports : textwidth 0 textheight 14 (but that 14 is coming from font size ) try changing font-size you will get different value even if textarea is completely empty.

                        • 9. Re: TextArea.textWidth &amp; TextArea.textHeight
                          WandiZhang Level 1
                          Hi,

                          I am not sure to understand you well...

                          What are you referring as *pseudo container (invisible)* ?

                          In my code, I set the container to be 600 (width) X 100 (height).

                          When I run the code, it gives me 100 (width from textWidth) X 293 (height from textHeight).

                          And the text is displayed according to the 600 X 100 container.

                          If you referred the pseudo container as one "imaginary container created by Flex (or the compiler) without consideration to the real layout container", than it makes the textHeight and textWidth properties completely useless.

                          That is why I questioned the seriousness of this implementation since it will never return the expected results...
                          • 10. Re: TextArea.textWidth &amp; TextArea.textHeight
                            levancho Level 3
                            You only get 100 (width from textWidth) X 293 (height from textHeight). very first time when component loads, as soon as you start typing from very first keystroke height and width are displayd correctly, (I have tested)
                            so to narrow it down problem is only with initial very first time displayed data to solve that I did following added "initialize="test.validateNow()"" to textarea component :

                            <mx:TextArea
                            id="test"
                            width="600" height="100"
                            wordWrap="true"
                            text=" iofjw oiajwe ofij
                            oawijefawoigjeruhiofjw oiajwe
                            ofij oawijefawoigjeruhiofjw oiajwe
                            ofij oawijefawoigjeruhiofjw oiajwe ofij oawijefawoigjeruhiofjw oiajwe ofij oawijefawoigjeruh awuiohefiaw uhefioj ioawej oaiwje foijawoegjao oaiwjf eoahegiu awiuh iawhefhawihef iawuhef iauwhef iawefh iruhg uerh greg oawjeifioawj efoiawje foawrhgi awerghiawheiua wfiehawefiuhawie fawie fawi f aw efawfhawei fawihfe iawuhfi aweiawiue iawhfeiuaw fiawehf iawehf "
                            creationComplete="_check()" initialize="test.validateNow()">