18 Replies Latest reply on Oct 18, 2010 9:34 PM by rubixchick19

    (Help) Using Input text in Flash CS4 AS3

    SecretSpider

      I am trying to take a user's input (His Name) and then greet the user on the next frame using the name he previously entered. I googled for 2days and was unable to find a way to do this on flash CS4 AS3, i guess because im very new to flash (only 2-3weeks )
      Any help would be greatly appreciated, and i am sorry if this was already answered in the forums.
      thanks for reading.

        • 1. Re: (Help) Using Input text in Flash CS4 AS3
          Ned Murphy Adobe Community Professional & MVP

          You essentially need to capture the user's entry and commit it to a globally accessible variable.  For the golbally accessible variable, you can use create one by having a timeline actions layer that extends the full length of the timeline and coding in the following in frame 1...

           

          var hisName:String;

           

          Then you need to assign the text the user entered into that variable.  This can be done either by coding a button to assign it or by monitoring the textfield for changes.  Let's say you give the textfield an instance name of userName.  Then whatever method you prefer for assigning the value would be...

           

          hisName = userName.text;

           

          And from that point forward, you can utilize the hisName variable when you want to use the name in some text box...

           

          greeting.text = "Welcome "+hisName;

           

          If you need more help, identify which version of actionscript you are using.  For any other coding help you might need for what's been described here, knowing that will be necessary.

          1 person found this helpful
          • 2. Re: (Help) Using Input text in Flash CS4 AS3
            SecretSpider Level 1

            Thanks alot ned.

            What you said with the following code and when i control+enter it gives me 2 errors

             

            stop();


            var hisName:String;


            btnEnterName.addEventListener(MouseEvent.CLICK,EnterName);


            function EnterName (event:MouseEvent):void
            {
            hisName = EnterName.text;

            }

             

             

            1)1023: Incompatible override.

            2)1021: Duplicate function definition.

             

            I am using flash Action Scrpit 3.0

            and once again thank you very much.

            • 3. Re: (Help) Using Input text in Flash CS4 AS3
              Ned Murphy Adobe Community Professional & MVP

              While I'm not familiar ith that first error you list, chances are your use of EnterName for the function name and the textfield name is the source of the error messages... You can't use the same name for different things.

              1 person found this helpful
              • 4. Re: (Help) Using Input text in Flash CS4 AS3
                SecretSpider Level 1

                Wow thanks for the reply yes using the same name caused the problem

                A new problem

                I created a dynamic text field on the second frame and gave it an instance name of "NewName"

                When i test the movie, it works, and the input text field is displayed, and when i enter a string and hit the button..... i get the following error ..

                 

                TypeError: Error #1009: Cannot access a property or method of a null object reference.
                     at Project_fla::MainTimeline/EnterNameOK()

                 

                 

                 

                 

                stop();


                var hisName:String;



                btnEnterName.addEventListener(MouseEvent.CLICK,EnterNameOK);


                function EnterNameOK (event:MouseEvent):void
                {
                NewName.text = hisName;
                gotoAndStop(2);


                }

                 


                Thanks

                • 5. Re: (Help) Using Input text in Flash CS4 AS3
                  Ned Murphy Adobe Community Professional & MVP

                  I believe in this case you're putting the cart before the horse.  The variable is what the function is going to assign value to, correct?  You have the textfield being assigned the variable, which at that point is an undefined value.  Try to think thru what you are doing as you do it.

                  • 6. Re: (Help) Using Input text in Flash CS4 AS3
                    SecretSpider Level 1

                    Ahhhhhh thank you very very very much......

                    For the gudance i really really appriciate it.

                    Thank you

                    • 8. Re: (Help) Using Input text in Flash CS4 AS3
                      erikphanson

                      Thread is over a year old and still helped me. Couldn't find a pointer in the right direction anywhere until I tripped on this. Thanks!

                      • 9. Re: (Help) Using Input text in Flash CS4 AS3
                        AriAE11

                        there's an easier way:

                         

                        on the input text, put something in the field "var"

                         

                         

                        in dynamic text, in the next frame (or anytime)

                         

                        put the same thing in the field var

                         

                         

                        -ari

                        • 10. Re: (Help) Using Input text in Flash CS4 AS3
                          Ned Murphy Adobe Community Professional & MVP

                          Unless AriAE11 can provide a better explanation, I recommend paying no attention to what has been offered.  If this regards the "var" field of a textfield in the Properties panel, AS3 discontinued this and does not support this... and as an AS2 feature it can be problematic to use it and is better off avoided.

                          • 11. Re: (Help) Using Input text in Flash CS4 AS3
                            rubixchick19 Level 1

                            Ah, I was looking for this! Your explanation gave me a good headstart on this problem. I followed your advice to SecretSpider's post on how to get the Input text field to work so that he could greet his visitor by name on another page. I've got the input field working but my problem is that the text isn't showing up in the output box. I've done traces, and when testing, I get no errors. This is what I have:

                             

                            var myName:String;

                            myName = confirm_txt.text;

                            confirm_txt.text = "So your name is "+ myName;

                             

                            myName is the instance name of the input text field I placed on my stage. confirm_txt is the instance of the dynamic text field where I expect the input to be shown while the user is typing in the input before confirmation. So when I test, I can type in the input but nothing is showing in the dynamic box except for the words I wrote "So your name is..." I imagine I need to put a button to "enter" it as you were explaining earlier? An event and a listener? I want to be able to call on that name at any point later after the user has inputted it, but I just can't seem to get this basic start working...

                             

                            Sorry for intruding on this post. I've been going crazy trying to solve this small problem. Someone had given me AS3 to copy where he/she had literally drawn in the text fields using AS3 and it works but I don't want that. It seems too complex to had the AS3 do all that when you can just use a tool to draw it and move it where ever you want. I want to be able to use the text tool to make my boxes, name their instances and then do whatever I need to do in the Actions panel- it feels easier for me that way.

                             

                            Anyway, thanks for the headstart on this old thread and if you happen to offer me any advice, thank you in advance!

                            • 12. Re: (Help) Using Input text in Flash CS4 AS3
                              Ned Murphy Adobe Community Professional & MVP

                              I had to laugh at your mention of "Someone had given me AS3 to copy.... and it works but I don't want that" because that person and I have a disagreement involving that approach to helping people who are beginning to learn Actionscript and/or Flash.

                               

                              You should continue with the posting you already had going.  Don't be afraid to indicate you didn't want or didn't know how to adapt what you were given--that kind of feedback is important.  Marking something as answered for something that didn't answer your needs leaves the wrong impression.

                               

                              You will probably find if you look closely at the solution you were handed that it does not work correctly though it might appear to.  The TextEvent.TEXT_INPUT event fires before the new input is written, so you won't see what you just typed in the output textfield... it will always be one letter behind where the input text is.  You should instead use the Event.CHANGE event which occurs after the entry is made.  Alternatively, the TEXT_INPUT event carries the text that was entered in it so you could also use the following to get all of the entered text to show....

                               

                              outputField.text = "You typed " + inputField.text + e.text;

                              • 13. Re: (Help) Using Input text in Flash CS4 AS3
                                Ned Murphy Adobe Community Professional & MVP

                                Also, you shouldn't tag on to someone else's posting for your own problems, especially postings that are marked as answered and quite old--they are easily overlooked. It was just chance that I decided to look at this posting.

                                • 14. Re: (Help) Using Input text in Flash CS4 AS3
                                  rubixchick19 Level 1

                                  I'm sorry. I've never posted to forums before so this is all a first for me. I apologize if I was rude. I'm sorry.

                                   

                                  And you're completely right. I'll see what can be resolved from my original post. I know that this person is trying to help and they're very advanced so he/she is trying to explain it all to me, and I think I'm a bit more confused than when I started with all the script they're throwing at me haha. I had marked it answered because it was answered, just maybe not exactly which I felt might have been my own fault since in my post, I asked like 10 different questions rather than 1 clear one. Well, I'll see what happens.

                                   

                                  And you're right, I did have that problem with the actionscript that was given to me, it worked but it was always a letter behind unless I put a space after what I've typed so it could catch up. I'll def try out your suggestion.

                                   

                                  Thank you for the advice and once again, I apologize for my rudeness. Take care.

                                  • 15. Re: (Help) Using Input text in Flash CS4 AS3
                                    Ned Murphy Adobe Community Professional & MVP

                                    There was nothing rude about what you did, so I'm sorry if I gave that impression.  And while I'm not sure what you think might have been considered being rude, my only real concern in what I said was to help you maximize your potential for getting help.  When you stick with what you start, the folks that helped are likely to keep trying.

                                    • 16. Re: (Help) Using Input text in Flash CS4 AS3
                                      rubixchick19 Level 1

                                      I was worried that I was being offensive by jumping into an older post and neglecting the one I originally had, is all. But in the end, you were right. I did tell the person what I wanted and am hoping for results.  I will make sure to be clear on what I want and not be hesitant with it. I'm still adjusting on how to use forums. Although my post has sort of strayed from its original intention, he/she really is offering me some useful tips for later on.

                                       

                                      Thank you for the words! Take care.

                                      • 17. Re: (Help) Using Input text in Flash CS4 AS3
                                        Ned Murphy Adobe Community Professional & MVP

                                        If your interested... here's some general "rules of the road" that are basically courtesies...

                                         

                                        Don't post the same question in different forums (crossposting).  Folks that help don't like that because they can waste their time providing the same response someone else already offered elsewhere, or their helpful info gets no attention because the OP (original poster) got wrapped up in the discussion elsewhere and never went back to the other forums.  I saw one time where the OP suffered from doing this... the first person to respond in one forum said what they wanted couldn't be done, while my response in another forum showed them how to do it... but they accepted that it couldn't be done and never returned.

                                         

                                        Don't post in someone else's posting unless the exact same situation applies to you and it is a current posting.  It is a bit rude to step into someone else's posting just to get attention, which some people do... some with totally unrelated problems.  Or if your problem is even slightly different, it can end up confusing matters for all involved... trying to juggle helping two people where different solutions are needed.

                                         

                                        If you get one problem resolved and have another you want help with that does not involve the first, start a new posting.  People search these forums so it helps to have topics match the postings, which will not apply if mutliple topics get resolved under one title.  I recently saw one person tell someone to start a new posting even though they were following up to clarify something of the solution they received... that's wrong and is more likely someone with a case of points greed... as useless as points are, it happens.

                                        1 person found this helpful
                                        • 18. Re: (Help) Using Input text in Flash CS4 AS3
                                          rubixchick19 Level 1

                                          Ah, that definitely helps. I'll keep it all in mind, especially in the future. I expect to run into other questions I have and after this first post of mine, learned that maybe it's better to ask one clear question in one post to get the clearest answer possible rather than how I asked and sort of threw extra questions into the post.

                                           

                                          And despite that I went against the "rules of the road" just this once, it turned out all right. I managed to learn a lot, both to solve my problem and also how to post on forums to get the best results. It might have been a necessary mistake on my part. Anyway, I'm grateful for the time you've put into explaining it all to me and helping to solve my problem. Thanks again!