5 Replies Latest reply on Feb 13, 2008 12:57 AM by vij010

    populating a textarea

    vij010
      Hi,

      I am using a Textarea and i want to add items to the textarea from a text input field. So, as I enter items through the textfield on screen, the textarea will update showing the items one below the other.

      I have a code snippet here :

      var TextRow:TextLineMetrics
      TextRow=mylist.getLineMetrics(mylist.textHeight)

      Would this give the current rowIndex of the TextArea ?...My idea is to add a new Row and use that to populate the new item returned from the textfield. But it doesn't work...
        • 1. Re: populating a textarea
          atta707 Level 2
          how about just appending \n before every entry?
          • 2. Re: populating a textarea
            vij010 Level 1
            Hi,

            I don't get what you mean...I tried this...

            mylist.text=mytext.text+"\n"

            but what happens here is that there is a new line, but subsequent additions are still updated on the same line, it does not drop one after the other like.....

            one
            two
            three

            Instead it changes on that single line itself, that's why I was wondering if I needed something advanced for this....
            • 3. Re: populating a textarea
              vij010 Level 1
              This is what I am trying to do. The textarea gets populated from a textfield.


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="469" height="322">
              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.controls.TextArea;
              import flash.text;


              public function update():void
              {

              if(mytext.text=='')
              {
              Alert.show('Enter Text')
              }
              else
              {
              mylist.text=mytext.text+"\r"
              }
              }
              ]]>
              </mx:Script>
              <mx:Panel x="10" y="10" width="449" height="302" layout="absolute">
              <mx:VRule x="180" y="10" height="242"/>
              <mx:LinkButton x="297" y="135" label="Update List" enabled="true" click="update();"/>
              <mx:TextInput x="219" y="105" id="mytext"/>
              <mx:TextArea x="10" y="10" height="242" id="mylist"/>
              </mx:Panel>
              </mx:Application>
              • 4. Re: populating a textarea
                atta707 Level 2
                Here is the culprit line for you:

                mylist.text += mytext.text + "\n"

                You need to concatenate new string to exiting text in text area instead of replacing it.

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="469" height="322">
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                import mx.controls.TextArea;


                public function update():void
                {

                if(mytext.text=='')
                {
                Alert.show('Enter Text')
                }
                else
                {
                mylist.text += mytext.text + "\n"
                }
                }
                ]]>
                </mx:Script>
                <mx:Panel x="10" y="10" width="449" height="302" layout="absolute">
                <mx:VRule x="180" y="10" height="242"/>
                <mx:LinkButton x="297" y="135" label="Update List" enabled="true" click="update();"/>
                <mx:TextInput x="219" y="105" id="mytext"/>
                <mx:TextArea x="10" y="10" height="242" id="mylist"/>
                </mx:Panel>
                </mx:Application>
                • 5. Re: populating a textarea
                  vij010 Level 1
                  Thank you so much for your guidance. I was not concentrating on why I could not concatenate, rather I was concentrating on assigning it.