4 Replies Latest reply on May 22, 2006 10:53 AM by JohnKirk

    How to persist TextInput text values?

    JohnKirk
      Can anyone provide a brief explanation of how to persist text values?

      Description:
      Stuff written into a TextInput field does not persist when moving
      to another frame, and back again.

      Example:
      Frame 1: Put a TextInput component on the stage.
      Frame 1: Put a "forward" button on the stage.

      Frame 9: Put a "back" button on the stage.

      Frame 1 actionScript:
      this.btnForward.onRelease = function() {
      gotoAndStop(9);
      }
      Frame 9 actionScript:
      this.btnBack.onRelease = function() {
      gotoAndStop(1);
      }
      Play it.
      Write something in the TextInput.
      Click the forward button. (this takes it to Frame 9)
      Click the back button. (this takes it back to Frame 1)
      >> The TextInput field is blank.

      Hoping someone can help,
      Thanks,
      John
        • 1. Re:  How to persist TextInput text values?
          2m Level 2
          Just store the value of the textfields content in some variable when moving away, and retrive it when movin to that frame to set the textfields "text" property to the stored value.
          • 2. Re:  How to persist TextInput text values?
            JohnKirk Level 1
            Hi,
            Thanks for your quick reply!! -- still have a problem, as follows: Value gets set to "undefined" upon return.

            Can you go into just a little more detail about "where" the variable should be created, and "when" it should be populated and read?
            Details:
            Frame 1:
            1) I declare a variable in Frame 1, and initialize it to null:
            "var myStr:String = "";"
            2) I save the value in the btnForward.OnRelease function:
            "myStr = Ti.text;"
            3) I add a line to set the TextInput text: "Ti.text = myStr;"
            4) When I Play it, Ti is empty. I type in words, and click forward (moving to Frame 9). Then I click back (moving to Frame 1). Ti shows "undefined".

            Thanks for your patience,
            John
            • 3. Re:  How to persist TextInput text values?
              2m Level 2
              quote:

              Originally posted by: JohnKirk
              Hi,
              Thanks for your quick reply!! -- still have a problem, as follows: Value gets set to "undefined" upon return.

              Can you go into just a little more detail about "where" the variable should be created, and "when" it should be populated and read?
              Details:
              Frame 1:
              1) I declare a variable in Frame 1, and initialize it to null:
              "var myStr:String = "";"


              That seems reasonable (thoug technically you set it to an empty string and not to null, but the empty string is better in this case)
              quote:


              2) I save the value in the btnForward.OnRelease function:
              "myStr = Ti.text;"


              when using the button this way you would have to use
              "this._parent.myStr = this._parent.Ti.text";
              as the scope in buttons behaves different if you put the action directliy on the button (flash 5 way) or if you do it your way.
              quote:


              3) I add a line to set the TextInput text: "Ti.text = myStr;"
              4) When I Play it, Ti is empty. I type in words, and click forward (moving to Frame 9). Then I click back (moving to Frame 1). Ti shows "undefined".

              Thanks for your patience,
              John


              I hope that helps.
              [I have to put my kids to bed now, so it'll be a while before I can help if it won't work as I expect.
              Anybody else also is very welcome to help ;-) ]
              • 4. Re:  How to persist TextInput text values?
                JohnKirk Level 1
                Many Thanks!
                You have provided me with the basic answer -- Plus some areas to investigate, as follows:

                1) I need to investigate the syntax within differing Scopes.

                (I'll reiterate for any future readers)

                2) The syntax within the function call is:
                "this._parent.myStr = this._parent.Ti.text;"

                3) The syntax outside the function call is:
                " this.myTi.text = this.myStr;"

                Many Many Thanks!!!
                --John