4 Replies Latest reply on May 5, 2010 7:37 AM by EKonopka

    Need help: loading movies

    EKonopka

      I have a problem I'm hoping someone can help me out with.  I have used the loadMovie function to load another .swf into the current movie.  In the first movie the user inputs a name into an input text box, the contents of which is then saved into a variable called "yourname" (I've used trace commands to confirm that this much is in fact working).  When I load the next movie, I want to reference that variable in a dynamic text, but the variable isn't being "passed" to the loaded movie clip (in other words, I created a test button that serves no other purpose than to trace the variable, and it comes up as "undefined").  How do I get a loaded movie clip to "reference" variables in the main timeline/movie clip?

       

      Any help would be great!

       

      --Evan

        • 1. Re: Need help: loading movies
          Ned Murphy Adobe Community Professional & MVP

          Your loaded movie will probably need to use _parent references to target the textfield... as in _parent.textFieldName.text.  You could also try using _root instead of _parent.

          1 person found this helpful
          • 2. Re: Need help: loading movies
            EKonopka Level 1

            I put the _parent... code into the "variable" property field of the dynamic text box in the loaded movie, and sure enough it worked!  Thanks for that bit of info, that's really great!

             

            But...

             

            There has to be a way for loaded movies to be able to truly "reference" variables from the previous movie.  In other words, a way that info that the user submits in the previous movie to be accessible in the loaded movie, and vice-versa.

             

            Any thoughts/suggestions?

            • 3. Re: Need help: loading movies
              Ned Murphy Adobe Community Professional & MVP

              That does truly reference variables from a previous movie.  You'll need to describe what would come closer to doing that if you think it doesn't.

               

              It all comes down to storage and retrieval.  You need to store data somewhere that it can be made available, and you need to make your movie capable of retrieving the data from those data resources.

               

              Using _parent, while frowned on in the general OO world is as valid as any approach when it comes to accessing data in a _parent object.  You could also try using _global variables, but those are even more frowned upon, and were discontinued as an available built-in option in AS3.

               

              You could write data to some form of database (MySQL db or XML file) and use that as the data storage vehicle, and then you would have to build in the ability for your movies to extract data from those resources.

              1 person found this helpful
              • 4. Re: Need help: loading movies
                EKonopka Level 1

                First off, thanks for responding to my post to try to help this Flash newcomer out.  I've only been working with it for a couple months and am still very green.

                 

                You're right when you say it comes down to storage.  I believe that is where I am having my difficulty.  Perhaps some screenshots will help illustrate my quandry (note: the project does not look great at this stage.  Right now I am only concerned with figuring out the functionality):

                 

                Picture-1.jpg

                I've entered my name and am just about to click the submit button, the code for which is:

                 

                on (release) {

                     yourname = String (inpt_name.text);

                     trace (yourname);

                 

                     loadMovieNum ("project1.swf", 1);

                 

                }

                 

                Fairly simple enough--I'm just taking the text in the input box and storing it as a variable called "yourname."  We then trace it, just to make sure it is taking the data from the box and storing it, then load the next movie clip.

                 

                Picture-2.jpg

                The trace works--as you can see in the output window it is properly getting my name.  The dynamic text box however is not displaying "yourname," it is instead displaying "_parent.inpt_name.text."  It works, but it is not the same--it is displaying the text contents of the input text box "inpt_name," which is located on the parent level, as opposed to displaying the contents of the variable named "yourname," which was declared and then had a value given to it on the parent level.  I had to do it this way because when this movie loads it is no longer recognizing the "yourname" variable.  For testing purposes I put the same trace command in the "home" button, and:

                 

                Picture-3.jpg

                now that value, which we proved DID indeed successfully get stored in "yourname," is gone.  That's the problem I am facing!  I'm not sure how to properly store the variable's value so that other movie clips and reference/change them.

                 

                Does that make sense now?  I probably didn't explain myself well enough before, but hopefully now I have.  Like I said before, I am still rather new to this and could use any help I can get.

                 

                --Evan