3 Replies Latest reply on Oct 10, 2007 7:07 AM by Sivakanesh

    How do I write in a variable what a user writes in an inputTextField?

    Venian Level 2
      I want what is written by a user in an inputTextField to be written down in a variable for further use. I want the action to be triggered when i press "Enter".

      Can someone help me?

      Thanks very much.
        • 1. Re: How do I write in a variable what a user writes in an inputTextField?
          Sivakanesh
          If you know how to create classes in actionscript then you can store the values in the Class members. However if you don't the quickest way to store a value is
          _root.yourVariableName = "your value";

          This will exist for the live of your movie and can be accessed by MCs at all levels.

          To get a function triggered on Enter you need to add an eventListner for your TextBox.

          Key.removeListener(nameOfYourTextBox);
          nameOfYourTextBox.onKeyDown = function(){
          if(Key.isDown(Key.ENTER)){
          //functionToExecute();
          }
          }
          Key.addListener(nameOfYourTextBox);
          • 2. Re: How do I write in a variable what a user writes in an inputTextField?
            Venian Level 2
            it doesn't work.

            I have like this. frame 1 an input field in which i write something. on <Enter> i want it to move to frame 2 but also to record the text in a variable. on frame 2 i have a dinamicTextBox (created at authoring time) in which i want to be written what is written in the variable, being given that the variable contains what was written in the input text field.
            • 3. How do I write in a variable what a user writes in an inputTextField?
              Sivakanesh Level 1
              Well it all depends on where you have put the code;
              Put the code below on Frame1. Assuming the instance name of your inputcontrol is 'nameOfYourTextBox'.

              Key.removeListener(nameOfYourTextBox);
              nameOfYourTextBox.onKeyDown = function(){
              if(Key.isDown(Key.ENTER)){
              trace("enter key is pressed");
              _root.myVar = nameOfYourTextBox.text;
              gotoAndPlay(2);
              }
              }
              Key.addListener(nameOfYourTextBox);
              stop();

              If your inputbox name is different then change it in the above code. There are 3 places in the code.
              in frame 2, trace the variable _root.myVar to makesure you have picked it up.