9 Replies Latest reply on Jan 21, 2011 8:00 AM by Cuwen_26

    No loop in swf array?

    Cuwen_26

      Hey everyone.  So, I have this flash movie I've been working on for awhile.  Everything's going great thanks to a lot of help I've received in these forums.   I have my file set to load an array of swfs.  Now, though, I'm wondering how to keep it from looping.  At the end of the last swf, I want the movie to go to the last swf and then just stop.  Here is my code:

       

          var listener:Object = new Object();
          var mcl:MovieClipLoader = new MovieClipLoader();
          mcl.addListener(listener);

             // When the swf loads, set it up to constantly check its current frame
          // against the total frames, and if those match, the swf is done playing.
          // If that's the case, then load the next one.

          listener.onLoadInit = function(targ:MovieClip):Void {
             theTargetClip_mc.onEnterFrame = function():Void {
                if (this._currentframe == this._totalframes) {
                   loadNext();
                   delete this.onEnterFrame;
                }
             }
          }


      //Previous and Next Swf Buttons

      function loadNext():Void {
          currentSwf++;
          if (currentSwf >= swfs.length) currentSwf = 0;
          loadSWF(currentSwf);
      }


      function loadSWF(nextSWFToLoad){
         mcl.loadClip(swfs[nextSWFToLoad],theTargetClip_mc);
      }


      loadSWF(currentSwf);


      function loadPrevious():Void{
         currentSwf--;
         if(currentSwf==-1) currentSwf = swfs.length-1;
         loadSWF(currentSwf);
      }


      previous_btn.onRelease = loadPrevious;
      next_btn.onRelease = loadNext;

      //End Previous and Next Swf Buttons


      //Play Button

      play_btn.onRelease = function() {
          theTargetClip_mc.play();
      }

      //Pause Button

      pause_btn.onRelease = function() {
          theTargetClip_mc.stop();
      }

        • 1. Re: No loop in swf array?
          markerline Level 4

          If this is AS2.0 I might not give you the best help.  Alas, I am still learning AS3.0 anyway.

           

           

          However I do see that you are resetting "currentSwf" to "0" which I think is causing the engine to go back to the first SWF, am I right?

          • 2. Re: No loop in swf array?
            Cuwen_26 Level 1

            Yeah.  It's AS2.  I'm not even much of a coder myself.  I'm mostly a designer with a very thin grasp on coding.  That code was created for me by someone else and I copied and pasted it into my Flash file.  Even though they tried to explain it to me, I still don't really understand it.  The 0... I think means that if it's greater than the first swf, load the next one?  Honestly, not sure.

             

            I wish I understood AS2 better.  I can understand the basic stuff really well, but when it gets into var and controlling an array, I'm lost.  I'd love to get a tutorial book that explores AS2 or AS3 better, but I haven't found one, yet.

             

            I was hoping there was a quick code to put in there that would just stop it from looping.

            • 3. Re: No loop in swf array?
              markerline Level 4

              Again, not being AS2 proficient (although I used to know a little bit), what it looks like is happening is you have currentSwf++ which is incrementing that variable each time the "next" button is pressed.  The same thing happens in reverse when the "previous" button is pressed.  From what it looks like, currentSwf is resetting to zero once it reaches the ".length" of the swf array--you will see the .length term in your if statement in the same place.  So you have to create an extra condition with somehow adding a listener to check that the full length has been reached and then do not load any more swf's and in addition stops the last swf from playing or removes it from the stage and replaces it with some image indicating that all swf's in the array have been played. 

               

              Does that make sense?

              1 person found this helpful
              • 4. Re: No loop in swf array?
                Cuwen_26 Level 1

                Thanks.

                  It does make sense to a certain extent... but I still don't know how to make that extra condition and have it not interfere with the rest of the movie.  I need something that says when last swf is done playing, the movieclip stops.  See, what I'd like to do is put the menu swf that I have at the end of my list of swfs so that the movie goes to the main menu and the user can click where they want to go next.  However, with the array on loop, it flashes to that menu swf but then goes right back to the beginning of the array.  I want it to stop at that last swf, the menu swf.

                • 5. Re: No loop in swf array?
                  Cuwen_26 Level 1

                  Does anybody know how to add that kind of code to the code I already have?  Help would be very much appreciated!!  I'm really curious to see how this would be done.

                  • 6. Re: No loop in swf array?
                    markerline Level 4

                    Cuwen_26 wrote:

                     

                    Does anybody know how to add that kind of code to the code I already have?  Help would be very much appreciated!!  I'm really curious to see how this would be done.

                     

                    NOTE:  take note of the SWF titles I have in the added Array declaration line . . . . (var swfs:Array=new Array("etc,etc,etc") below in the code)

                     

                    CODE:

                     

                    var listener:Object = new Object();

                     

                    //change the titles in the array to whatever your content swfs are called

                    //in your directory.  Store the swfs in the same directory

                    //as your FLA

                    var swfs:Array= new Array("swf_01.swf","swf_02.swf");

                    var container:MovieClip = createEmptyMovieClip("container",getNextHighestDepth());

                        var mcl:MovieClipLoader = new MovieClipLoader();

                        mcl.addListener(listener);

                     

                           // When the swf loads, set it up to constantly check its current frame

                        // against the total frames, and if those match, the swf is done playing.

                        // If that's the case, then load the next one.

                     

                     

                        listener.onLoadInit = function(targ:MovieClip):Void {

                                trace("loaded listener");

                    theTargetClip_mc.onEnterFrame = function():Void {

                              if (this._currentframe == this._totalframes) {

                     

                                 //loadNext();

                                 delete this.onEnterFrame;

                              }

                           }

                        }

                     

                     

                    //Previous and Next Swf Buttons

                    var currentSwf:Number=0;

                    function loadNext():Void {

                        currentSwf++;

                        if (currentSwf >= swfs.length){

                              //currentSwf = 0;

                              }

                        loadSWF(currentSwf);

                    }

                     

                     

                    function loadSWF(nextSWFToLoad){

                       mcl.loadClip(swfs[nextSWFToLoad],theTargetClip_mc);

                    }

                     

                     

                    //loadSWF(currentSwf);

                     

                     

                    function loadPrevious():Void{

                       currentSwf--;

                       trace(currentSwf+" currentSwf");

                       if(currentSwf==1) {

                            currentSwf = swfs.length-1-1;

                       }

                       trace(currentSwf+" currentSwf");

                       loadSWF(currentSwf);

                    }

                     

                     

                    previous_btn.onRelease = loadPrevious;

                    next_btn.onRelease = loadNext;

                     

                    //End Previous and Next Swf Buttons

                     

                     

                    //Play Button

                     

                    play_btn.onRelease = function() {

                        loadSWF(currentSwf);

                         

                    }

                     

                    //Pause Button

                     

                    pause_btn.onRelease = function() {

                     

                         mcl.unloadClip(theTargetClip_mc);

                         

                    }

                    • 7. Re: No loop in swf array?
                      markerline Level 4

                      Does the above code not work for you?

                       

                      Note, I use UnLoad to take the current swf off the stage with the pause_btn because I cannot seem to access the timeline of the loaded SWF to cause it to stop or play in mid-sequence the way that I think you intend for it to do.

                      • 8. Re: No loop in swf array?
                        Cuwen_26 Level 1

                        No, it doesn't... thanks for trying, but I don't want to change the whole code.  I just want something that will stop it from looping.

                        • 9. Re: No loop in swf array?
                          Cuwen_26 Level 1

                          Question has been solved in a different thread I started.  If anyone is interested in knowing the solution, they can see it here:

                           

                          http://forums.adobe.com/message/3417799#3417799