5 Replies Latest reply on Sep 20, 2011 8:23 PM by Ron Colmen


    Ron Colmen Level 2

      In my fla I've allowed the user to add text by clicking a button. This button creates a newTextField each time it's clicked. Also they are alowed to delete any TextField. The TextField's instance names are tf1, tf2, tf3, etc....


      How do I capture the text which is currently in there?


      E.g. if a uaer added tf1, tf2, tf3 and tf4 and then deleted tf2, how do I get the text entered in tf1, tf3 and tf4 in a seperate textfield by clicking a button?

        • 1. Re: (tf1tf2tf3tf4-tf2)
          Ned Murphy Adobe Community Professional & MVP

          You can store references to your textfields in an array.  When you add a textfield you add it to the array, when you remove a textfield, you remove it from the array.  You use the array to have the button process the text into the separate textfield.

          • 2. Re: (tf1tf2tf3tf4-tf2)
            Ron Colmen Level 2

            Thanks Ned!


            Something like this? correct?


            //on the timeline

            var textF:Array = [tf1, tf2];

            textF.length = 25;


            //within the add text onRelease action

            textF.push ("tf"+i);


            for(i = 0; i < 3; ++i){

                var textF:Array = [tf1, tf2];

                y_txt= textF[i].text;


            // how do I remove?

            • 3. Re: (tf1tf2tf3tf4-tf2)
              Ned Murphy Adobe Community Professional & MVP

              Not really like that. For a couple of those lines I have no idea what you are thinking


              var textF:Array = new Array();


              // when you add a new textfield...

              textF.push(the new textfield);


              // in the onRelease

              for(i=0; i<textF.length; i++){

                  y_txt.text += textF[i].text;



              // to you remove a textfield from the array you can use the Array.splice() method

              • 4. Re: (tf1tf2tf3tf4-tf2)
                Rothrock Level 5

                Also it is a good idea to learn to start counting from zero! So the first textfield should be tf0, tf1, etc.


                You'll notice that arrays in flash are zero based. In the example Ned gave you the first loop starts with i=0.


                Trust me, your life with Flash will be happier if you learn to start counting at zero.

                1 person found this helpful
                • 5. Re: (tf1tf2tf3tf4-tf2)
                  Ron Colmen Level 2

                  Thanks Rothrock!