5 Replies Latest reply on Jul 30, 2008 11:40 AM by Rothrock

    another loadMovie question

      i'm trying to target a specific frame within a loaded external swf. i read in an earlier post the attached code, but it doesn't seem to be working for me. i would appreciate any suggestions on how to achieve this.

        • 1. Re: another loadMovie question
          Rothrock Level 5
          The code you have given has no chance of working. So that previous post was in error as well. There is no way to go to a frame (labeled or numbered) before that frame is loaded, in other words until it is loaded in it doesn't exist!

          This kind of code says, "Okay flash start loading this movie, now go to a frame." There is no waiting in there for the movie to finish loading.

          So you need some way of waiting until the movie has loaded and then doing the gotoAndStop.

          I've got to rant for a moment here. Not directed at you, obviously you are new(ish) to Actionscript and don't know. But for heck's sake why in this day and age are people still using loadMovie? Since Flash 7 came out in 2003 there has been a better way. Why aren't people learning this? What can we do to change it? Okay, end rant!

          The best way to do this is to use the MovieClipLoader class. That has built in ways to know when the file has been loaded and then you can do what you need to do.

          var myMCL:MovieClipLoader=new MovieClipLoader();
          var listener:Object=new Object();


          So that code mostly does the same thing as before. However you were using the accursed loadMovie to load into the _root. It is generally a bad idea to replace the contents of the _root (or _level0) with some new content. There are a few little things that occasionally go wrong. But I just find it to be a bad idea. In this case the code that you hope to execute lives (I'm guessing) somewhere in _root or a child of _root. So if you replace root how could that code execute?

          So in my example I have the loadClip loading your swf into a movieClip called someClip. That is some clip that you have made to receive the content, maybe using createEmptyMovieClip or some other way.

          Anyways, so what does this code do? Well the MovieClipLoader class is explained in the help files, so read that. But then we create an object just to put our stuff in a nice place. We add a handler function that will get called when the MovieClipLoader throws an onLoadInit event. This is the event that happens when the clip is fully loaded and ready to go.

          Next we tell the MovieClipLoader that it should announce its events to the listener object. And we are all ready to wait until the b5 button is pressed. On the release of that button we tell the MovieClipLoader instance to load an external file into some movieclip.

          So the loading starts and when the clip has finished loading the MovieClipLoader announces to its listeners that the onLoadInit event has happened. There are other events as described in the help files. And they have all been announced, for example the onLoadProgress event was announced everytime there was some progress in the loading. But since there was no handler the event announcement fell on deaf ears as it were.

          Anyways since the listening object has an onLoadInit event handler defined the function executes and tells the target (the clip that the content was loaded into) that it should goto and play the "Contact" label.

          Makes sense? If you have any questions post back.
          • 2. Re: another loadMovie question
            dtodab Level 1
            thanks for taking the time to provide a detailed explanation of the preferred method.
            much appreciated.
            • 3. Re: another loadMovie question
              Rothrock Level 5
              Sure. Sorry if I was grumpy. I know you are just learning, but what sources are still encouranging people to use loadMovie? I think I need to make it my mission to get people off loadMovie!

              Some how we have to figure out a way that people get introduced to the MovieClipLoader first and don't meet loadMovie until they already know MCL! Anyways, good luck and let me know if you need anything else!
              • 4. Re: another loadMovie question
                JCaroon Level 1
                Hi Rothrock.

                I am trying to something similar to the other person you helped. I'm very new to AS and I have a problem.

                I am using this code from a tutorial.

                _root.currMovie = "homenav";

                I want to go to a specific frame in the homenav.swf. I realize that it needs to be loaded but I dont know then next step.

                • 5. Re: another loadMovie question
                  Rothrock Level 5
                  The code is almost exactly the same as given above. Just take the loadClip call out of the button event handler and change the name of the swf that you are loading to the name of your file.

                  Also in the loadInit event handler you will go to the frame you want to go to.