5 Replies Latest reply on Oct 28, 2010 12:06 PM by Rothrock

    Instance Name

    Ron Colmen Level 2

      How can I change an instance name of a text box when a button is clicked?

        • 1. Re: Instance Name
          Rothrock Level 5

          I think you can just change the name property by assigning a new name.

           

          textField1._name="someNewName";

           

           

          I don't quite understand why you would ever want to change the name of something. Seems like coding is generally confusing enough without the names of things changing all the time.

          1 person found this helpful
          • 2. Re: Instance Name
            Ron Colmen Level 2

            Thanks RR.

             

            I need the onChange function applied to specific text boxes depending on the selected button.

             

            Example:

            There is one input textbox, 10 dynamic text boxes and 10 buttons.

            When button1 is clicked and the text is being typed in the input text box, it will apply the text to a text box.

            then when button2 is clicked and the text is being typed in the same input text box, it will apply the text in to another text box.


            have you got a better way in achieving this?

            • 3. Re: Instance Name
              Rothrock Level 5

              Well since I don't know everything you are doing it is hard to say, but this is how I would approach the problem....

               

               

              var home:MovieClip=this;

               

              var count:Number=0;

              var totalTargets:Number=3;

               

              var inputText:TextField;

              var selectorButton:MovieClip;

              var curTarget:TextField;

              handleRelease();

               

              inputText.onChanged=handleChange;

              selectorButton.onRelease=handleRelease;

               

              function handleChange(){

                   curTarget.text = this.text;

                   // or what ever you need to happend on change function, but this is the simplest form

              }

               

              function handleRelease(){

                   curTarget=home["targetField"+(count++)%totalTargets];

              trace(curTarget);

                   inputText.text="";

              }

               

              So assuming you have 10 textfields named targetField0, targetField1, etc. on the timeline. And an input textfield named inputText. And a movieclip button named selectorButton. The text you type in the input field will show up in targetField0 to begin with and then each time the button is clicked the next target textfield will get the results.

               

              Is that sort of what you are trying to do?

              • 4. Re: Instance Name
                Ron Colmen Level 2

                Thanks RR.

                 

                Yes that is close to what I'm trying to achieve. Anyway below is my exact requirement:

                There are 10 buttons instead of 1 button as in your description (selectorButton). When each button is clicked and then when the text is being typed in the INPUT TEXT box it should always update a given text field. See my example below.

                -----

                E.g.

                BUTTONS instance names: selectorButton0, selectorButton1, selectorButton2, etc...

                Dynamic Text Field Instance names: targetField0, targetField1, etc...

                 

                When selectorButton1 is clicked and then when the text is entered in the Input Text box it should always update targetField1. When selectorButton4 is clicked and then when the text is entered in to the Input Text box then it should always update targetField4. etc...

                -----

                 

                One more thing. If the input text field is in _root.movieA1.movieA2, and then selectorButton1,selectorButton2,etc.. are inside _root.movieA1 and the targetField1, targetField2, etc... are inside _root.movieX1 how will that effect your code?

                 

                I really appreciate your help.

                • 5. Re: Instance Name
                  Rothrock Level 5

                  Well I'm going to have to leave some of it as "an exercise for the reader" as it were. But the general idea would be something like this:

                   

                  var home:MovieClip=this;

                   

                  var numClips:Number=3;

                  var curTarget:MovieClip;

                   

                  for(var i=0;i<numClips;i++){

                       var curButton:MovieClip=home.movieA1.["selectorButton"+i]

                       curButton.ID=i;

                       curButton.onRelease=handleRelease;

                  }

                   

                  function handleRelease(){

                       curTarget=home.movieX1["targetField"+this.ID];

                  }

                   

                  Or something like that. It is really hard to be sure about all the scopes since you have such "interesting" naming conventions. But you can use trace statements in your various handlers and places to see if you are getting the scope you think you should be getting and tweak it to refine that part. You will also need some of the stuff from before.

                   

                  The best way to figure this stuff out is to play around with it.

                   

                  Also you will notice I use a trick of making a "Home" variable that is the timeline I'm on and then using that instead of _root. That allows me to move the place of things or load this into another swf without having problems with _root.