6 Replies Latest reply on Mar 6, 2009 3:56 AM by Ned Murphy

    Linking to a certain frame when loading a swf

    Axellette
      I need some urgent help with linking in Flash. I have a main movie in which all my buttons are, this movie loads the other swfs in a contentHolder movie clip.

      Now the problem is that I need to link to a certain frame in the loaded swf.

      button_btn.onPress = function() {
      contentHolder.loadMovie("investment.swf");
      };

      Now in the investment.swf I want it to go straight to frame 5. I have done lots of looking online, but cant seem to find the answer. I think I need to use variables but am not sure.

      Any help would be really appreciated!
        • 1. Re: Linking to a certain frame when loading a swf
          kglad Adobe Community Professional & MVP
          you need to wait until loading is completed (or, at least, wait until frame 5 is loaded) before you can access it. ie, use preloader code or use the moviecliploader class to load your swfs and use its listener's onLoadInit() method.
          • 2. Linking to a certain frame when loading a swf
            Ned Murphy Adobe Community Professional & MVP
            If you use loadMovie, then you need some mechanism inside the swf itself to determine what action to take when it finally loads. You could try having a variable that gets assigned a value of 5 in the maintimeline when the button is clicked and have the swf check that value in its first frame and take the appropriate action (I don't know if this would be a victim of a timing/loading issue though).

            Another option would be to use the MovieClipLoader class (loadClip method) instead of loadMovie, along with an event listener so that you can take action on the loaded clip after it has loaded. According to the Flash docs, a loaded file takes over the mc it is loaded into, so you should be able to target the container instance by name and tell it to go to frame 5 after the loading is completed. I've never dealt with this targeting before, so it's hear-say on my part.

            The Flash help docs should provide an example of using the MovieClipLoader class with a listener.
            • 3. Re: Linking to a certain frame when loading a swf
              Axellette Level 1
              Thanks Ned, I like the sound of doing it with a variable.
              I am not much of a actionscripter, could you please tell me step by step what to do?

              So the actionscript for my button will be:
              button_btn.onPress = function() {
              contentHolder.loadMovie("investment.swf");
              };

              I'm sure I must add some thing here after investment.swf to call the variable?

              In the actual investment.swf, what is the code I must add on the first frame?

              Thank you so much for your help!!
              • 4. Re: Linking to a certain frame when loading a swf
                Ned Murphy Adobe Community Professional & MVP
                The variable approach is the less reliable. Here's an example using the MovieClipLoader and your scenario:

                var mcLoader:MovieClipLoader = new MovieClipLoader();
                mcLoader.addListener(this);

                button_btn.onRelease= function(){
                mcLoader.loadClip("investment.swf", contentHolder);
                }

                function onLoadInit(mc:MovieClip) {
                mc.gotoAndStop(5);
                // or contentHolder.gotoAndStop(5);
                }
                • 5. Re: Linking to a certain frame when loading a swf
                  Axellette Level 1
                  Thank you so much, works perfectly!
                  You have seriously saved my *** with this project!! This script is going to really help in the future too...
                  Can't thank you enough!