11 Replies Latest reply on Jan 15, 2013 8:26 AM by TACO

    Need help! My inputs are disapperaing in my frames.

    TACO

      I have 3 frames and each frame has a few textinput boxes and some checkmarks that I created. Every time I click to go to next frame my inputs and check marks erase on previous frame . Is there a way to keep he text in my textinputs while I move through my frames?

       

      Thanks

        • 1. Re: Need help! My inputs are disapperaing in my frames.
          Ned Murphy Adobe Community Professional & MVP

          You need to store the data that gets entered into variables if you want to return to a frame and restore the entries.  Create some variables in frame 1 of a layer that extends across the whole timeline for each field and assign them initial values of "" (or something similarly meaning nothing entered).  By extending it for the timeline, the variables will be available everywhere.

           

          When the playhead moves to a certain frame, you assign the values needed for inputs in that frame using the variables you created.  When someone enters a value, you need to take the value and assign it to its variable so that when you go back to that frame it is again assigning the value it currently has.

          • 2. Re: Need help! My inputs are disapperaing in my frames.
            TACO Level 1

            How do you assign the entered value to the variable?

            • 3. Re: Need help! My inputs are disapperaing in my frames.
              Ned Murphy Adobe Community Professional & MVP

              If these are input textfields you can assign an event listener for when the contents change and use that to trigger saving what is entered to a variable.  The code you need to use depends on which version of Actionscript the file is using.  Which version of Actionscript are your Flash Publish Settings set up for?

              1 person found this helpful
              • 5. Re: Need help! My inputs are disapperaing in my frames.
                Ned Murphy Adobe Community Professional & MVP

                Assign an instance name to each input textfield for which you wish to remember entries and assign code such as that shown below.  For the code below I use textfields with instance names of "entry1" and "entry2" with similarly named variables for each...

                 

                // frame1 code -  on a layer that extends the length of the populated timeline

                 

                var entry1Data:String;

                var entry2Data:String; // ditto

                 

                function assignData(evt:Event):void {

                     this[evt.target.name+"Data"] = TextField(evt.target).text;

                }

                 

                 

                // frame where entry1 and entry2 textfields are located

                 

                if(entry1Data != null) entry1.text = entry1Data;

                if(entry2Data != null) entry2.text = entry2Data;

                 

                entry1,addEventListener(Event.CHANGE, assignData);

                entry2,addEventListener(Event.CHANGE, assignData);

                 

                 

                The approach coded above is slightly different from what I described earlier.  In frame 1 the variables are only declared and not assigned a value.  In this way returning to frame 1 will not change them back to an intial value, they will retain whatever value they have acquired.

                 

                Also, the same function (frame 1 code) gets shared by all of the textfields, making use of the textfield name to target the variable associated with it... part of the reason for naming the variables the way they are. 

                1 person found this helpful
                • 6. Re: Need help! My inputs are disapperaing in my frames.
                  TACO Level 1

                       Thanks so much! Works like a champ. But I am curious how this would work with a text input component. I get this error when I use it:  TypeError: Error #1034: Type Coercion failed: cannot convert fl.controls::TextInput@373c9101 to flash.text.TextField.

                  • 7. Re: Need help! My inputs are disapperaing in my frames.
                    TACO Level 1

                    Disregard my last post I changed textfield to textinput in assignData function.

                     

                    Thanks again..

                    • 8. Re: Need help! My inputs are disapperaing in my frames.
                      TACO Level 1

                      I got two more Questions.

                       

                      How would I make this work with a ComboBox component to keep the selection I made from the drop down thought my frames ?

                       

                      I created a movieClip that is a checkbox that you click on that makes the check appear and click again to make the check disappear. How do I use this code to keep the same state I made the checkbox throughout my frames?

                      • 9. Re: Need help! My inputs are disapperaing in my frames.
                        Ned Murphy Adobe Community Professional & MVP

                        REgarding the code I showed earlier, I am noticing an error and I kinda woinder why what I provided works... but even I tested it before posting it for you and it worked... the error being I am showing commas where periods should be...

                         

                        entry1,addEventListener(Event.CHANGE, assignData);

                        entry2,addEventListener(Event.CHANGE, assignData);

                         

                        should be

                         

                        entry1.addEventListener(Event.CHANGE, assignData);

                        entry2.addEventListener(Event.CHANGE, assignData);

                         

                        So I guess commas can work as substitutes... though I recommend sticking with coding convention and using the dots.

                         

                         

                        As far as the combobox and checkbox go, you could use the same approach.  You just need to store the information in a variable.  For the combobox you could store the selectedIndex and use its assigned value to automatically set it when you get to that frame.  A value of -1 is used when nothing is selected.  The checkbox has a selected property that you set true or false.

                        • 10. Re: Need help! My inputs are disapperaing in my frames.
                          TACO Level 1

                          Thanks I caught on to the commas and I fixed that.. Thanks and I will try to apply this code to my questions and let you know...

                          • 11. Re: Need help! My inputs are disapperaing in my frames.
                            TACO Level 1

                            I been working with my checkboxes and cant seem to make it work. Here is my code

                             

                            // frame1 code -  on a layer that extends the length of the populated timeline

                            var cb1State:Boolean;

                             

                            function keepData(evt:Event):void

                            {

                                  this[evt.target] = MovieClip(evt.target)

                            }

                             

                            // frame where checkbox is located

                            if (cb1State == true)

                            {

                                  cb1.check_mc = cb1State;

                            }

                            cb1.check_mc.addEventListener(Event.CHANGE, keepData);