19 Replies Latest reply on Mar 11, 2007 10:18 AM by Social Psyence

    Passing text to new text fields

    Social Psyence Level 1
      Hello everyone. I've been going crazy with this trying to figure out why my variable isn't 'passing to another frame on the same scene. I declared a variable ( var sStudentParagraph:String = mcStudentWrite.text ). Where the "mcStudentWrite.text is the text inside an input text box.

      I trace the value of it after I click a submit button I made, and it shows me the value of whatever I happened to type in the input text box. The user is then lead to a screen witih a new dynamic text box that should display what they typed on the previous input text box. ( mcStudentWork.text = "you typed " + sStudentParagraph; ). But nothing loads into the "mcStudentWork" dynamic text box, I just get a value of undefined...

      I've worked with with numeric values before for scoring tests etc, and having the value load into a dynamic text box revealing their score, and tha'ts worked fine. I'm at a loss as to why this isn't working for me. Any insights will be most appreciated.
        • 1. Re: Passing text to new text fields
          kglad Adobe Community Professional & MVP
          is that string defined within a function?
          • 2. Re: Passing text to new text fields
            Social Psyence Level 1
            No, currently it's just a variable declaration. How would I go about turning it into a function exactly?
            • 3. Re: Passing text to new text fields
              willrose
              KGlad is just making sure you didn't create a local variable inside a function, because you wouldn't be able to access it anywhere else in your code.

              When you call this code:
              mcStudentWork.text = "you typed " + sStudentParagraph;

              is mcStudentWork on stage and visible at that moment? What I'm trying to get at is this. If you have that code in your submit button's onRelease event on say, frame 1, and the user is redirected to frame 5 where the new text box is, at the time that you call the code on frame 1, your new text box doesn't exist yet. If that is indeed your problem, you can make sure that your new text box is on your stage on frame 1 but invisible. When the time comes on frame 5 to show it, just set it's ._visible property to true.
              • 4. Re: Passing text to new text fields
                kglad Adobe Community Professional & MVP
                then where are you seeing "undefined"?
                • 5. Re: Passing text to new text fields
                  Social Psyence Level 1
                  So future text boxes have to be present on stage in order for them to work in the future? I had never realized this. The mcStudentWork text box is the new textbox that should be displaying the input text from the previous user submission, but it's on the stage on the frame in which it's needed to be seen, but not prior to that. The only text box the user sees prior to that is the StudentWrite text box.

                  But when I did my test scoring dynamic text box I never had to do that.

                  I used a variable declared at an earlier time, on a different frame, and when the score box needed the number of correct answers it displayed the correct number just fine.

                  I'm seeing the undefined when I trace the "sStudentWork" variable when I'm on the frame that has the dynamic input text box "mcStudentWrite". For some reason it seems like it's forgetting the variable from one frame to the next. I don't have the variable declaration inside a button function, it's the first thing I have written after the stop command.
                  • 6. Re: Passing text to new text fields
                    kglad Adobe Community Professional & MVP
                    objects only need to be present when they are referenced. so no, future needed textfields do not need to be present until they are needed.

                    who cares about trace(sStudentWork)? that's an unneeded complication or extraneous information.

                    what happens when you trace(sStudentParagraph)? if that's undefined then you're executing the trace function from a timeline different from the one that contains the sStudentParagraph assignment statement.
                    • 7. Re: Passing text to new text fields
                      Social Psyence Level 1
                      When I trace it in frame where the variable is intially set, it traces fine. It's when I move to another frame and trace the same varaible it becomes undefined...
                      • 8. Re: Passing text to new text fields
                        kglad Adobe Community Professional & MVP
                        you must have a typo. if you double checked your spelling/caps, post a link to your fla and specifiy the timeline and frames that contain the two traces.
                        • 9. Re: Passing text to new text fields
                          willrose Level 1
                          "objects only need to be present when they are referenced"

                          Exactly. I think my example was misunderstood. All I was trying to say was this. Say we have a submit button of frame 1. We have a textField on frame 5.

                          //frame 1
                          btnTest.onRelease = function():Void
                          {
                          txtTest.text = "Hello";
                          _root.gotoAndStop(5);
                          }

                          This code won't work because at the time we are trying to set the text, txtTest does not exist yet. I see people trying to do this all the time. That's all I was trying to get across.
                          • 10. Re: Passing text to new text fields
                            Social Psyence Level 1
                            I'll have to give a stripped down .fla, because the project is a monster of a file, it's part of this big project for my masters in educational technology.

                            I think I should be more clear, rather than it being "undefined", it's a null value. If I put the text "whatever" and trace on the first screen I'll get "whatever". But then move on to the next screen that calls on the variable I get nothing in the trace, just a blank line.. so it's not unedfined, but rather the text I entered doesn't seem to bind itself to the variable
                            • 11. Re: Passing text to new text fields
                              kglad Adobe Community Professional & MVP
                              next "screen"??? you're using screens? you probably have a path problem.

                              use trace(this) on the timeline of the "screen" where your variable is defined and use trace(this) on the timeline of the "screen" where your variable is undefined. post the results if you can't figure out the correct path.
                              • 12. Passing text to new text fields
                                Social Psyence Level 1
                                OK guys, one week later, same problem. I finally got the chance to work on this again, and I made a stripped down .fla file and posted it for anybody to review. If you can see what I'm doing wrong I'd be thrilled.

                                I'm notorious for overlooking the obvious, so I suspect it's something along these lines. Any help will be most appreciated..

                                Heres the link..

                                http://www.multimediablitz.com/enchantedpen/FLAFiles.htm
                                • 13. Re: Passing text to new text fields
                                  2m Level 2
                                  Hi,

                                  your mistake is, that you only once set the value of newText to the content of your text-field, and that is when the the text-field is empty, that leaves your variable with a value of an empty String (="").

                                  You get the undefined when tracing "textIn.text", because at that point in time(-line) no text-field with the name of textIn is present on stage (you renamed it to textOut on that frame).

                                  To solve the issue you have to assign the value of textIn.text to your variable inside your onRelease statements.
                                  • 14. Re: Passing text to new text fields
                                    Social Psyence Level 1
                                    Well, I had intitially set it as an inline fuction for the onrelease of the button, but when I did that I got the "undefined" on the following frame as well. Or are you talking about something different?
                                    • 15. Re: Passing text to new text fields
                                      2m Level 2
                                      the undefined comes from the line:
                                      trace(textIn.text);
                                      the next line of code produces an empty line inside the trace window.
                                      (as explained in my previous post.)
                                      • 16. Re: Passing text to new text fields
                                        Social Psyence Level 1
                                        I must be thick, but now I placed the variable inside the onrelease statment as you suggested but still get undefined..

                                        But when it moves to frame 2, it has no recollection of the variable and comes up undefined
                                        • 17. Re: Passing text to new text fields
                                          2m Level 2
                                          try:

                                          textIn.text = "enter type here";

                                          mcTest.onRelease = function():Void {
                                          this._parent.newText = this._parent.textIn.text;
                                          trace(this._parent.textIn.text);
                                          trace(this._parent.newText);
                                          };
                                          • 18. Re: Passing text to new text fields
                                            Social Psyence Level 1
                                            By jove, I think you've got it. So it needed to be in the function to properly set the value for the variable, but I needed to then to reference it properly by including the full path?

                                            I still get an "undefined" for one of my trace values on frame two, but the text box fills itself with whatever I entered in for type on the previous screen.

                                            Much thanks for you help!
                                            • 19. Re: Passing text to new text fields
                                              Social Psyence Level 1
                                              One question, however.. where is the declaration of the variable?