2 Replies Latest reply on Dec 21, 2007 1:39 PM by Garyl Woolworth

    Dynamic width in TextArea Component

    Tikis_Mikis
      Hello! So I have dynamically created panels that display text in the title depending on data returned in a result set from a DB call. I used a panel because it was the quickest thing I could think of when generating my dynamic components.

      However I dont want to use a panel for each element because all I am using is the title section of a panel to display the name of the row. So what I am trying to do is dynamically create Text or TextArea components in order for the name to be displayed in it. However, I cant for the life of me seem to figure out how to make the TextArea dynamically readjust its size depending on the text being displayed in it.

      In other words if my text is a total of 15px long then I would like my TextArea to readjust its size for example from 10px wide to 20px wide. If the next record I loop through is 30px then I want the TextArea to resize to 35px... and so on and so on.

      Am I using the wrong component? Should it be a label instead? I didn't want to use a Label component because I can't change background colors and set rounded edges as I can in a TextArea component. Please keep in mind I'm generating these TextAreas dynamically in Actionscript.
        • 1. Re: Dynamic width in TextArea Component
          Tikis_Mikis Level 1
          Ok you know what..I just decided to use Button component instead...it resiazes itself depending on thext length.....hmmm not sure if thats the best option but it certainly is the easiest
          • 2. Re: Dynamic width in TextArea Component
            Garyl Woolworth Level 1
            Well if you are still interested in using a text component instead of a Button the way you would go about this is using textWidth. Here's how I've done it before using a text / label whatever you want that shows text.

            // => Set our text we got from database
            myText.text = "This is the text I got from the DB";
            // => Validate it so that way we make sure we get right numbers
            myText.validateNow();
            // => Find out how wide our text really is.
            var textWidth:Number = myText.textWidth
            // => Reset the width of our text component and add 20 for a little buffer
            myText.width = textWidth + 20;

            Now my suggestion is if your going to be dynamically creating these on the fly from a database call you throw it into a method / class and have that do all the work for you so all you have to do is pass the text to it and it resizes itself based on the example above.