Jump to content
Search Community

How To Loop Sequence of SWF Files?

dragon test
Moderator Tag

Recommended Posts

 

Hi all... Is there anyone here???

I've found a simple but useful code  developed a few years ago... it loads 2 swf files in sequence ...

But I have just one question...

How can I Loop them?

How can you change the code to load swf1 after swf2 is finished?

I've tried almost the whole day but no result yet... Please help...

thank you a lot...

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.events.Event;


//create SWFLoaders


var swf1:SWFLoader = new SWFLoader("child1.swf",{container:this,y:100,onProgress:progressHandler,onComplete:completeHandler,autoPlay:false});
var swf2:SWFLoader = new SWFLoader("child2.swf",{container:this,y:100,onProgress:progressHandler,onComplete:completeHandler,autoPlay:false});
var currentSWFLoader:SWFLoader = swf1;


//adjust the progress bar;
function progressHandler(e:LoaderEvent):void {
    bar.scaleX = e.target.progress;
    trace(e.target.progress);
}


//tell the loaded swf to play and start tracking frames
function completeHandler(e:LoaderEvent):void {
    //the target of the LoaderEvent is the SWFLoader that fired the event
    //the rawContent is the loaded swf
    e.target.rawContent.play();
    addEventListener(Event.ENTER_FRAME, checkFrame);
}


function checkFrame(e:Event):void {
    //check to see if loaded swf is done playing
    if (currentSWFLoader.rawContent.currentFrame == currentSWFLoader.rawContent.totalFrames) {
        trace("swf done playing");
        removeEventListener(Event.ENTER_FRAME, checkFrame);


        //if the first swf is done playing load the second swf
        if (currentSWFLoader == swf1) {
            currentSWFLoader.dispose(true) // dispose and unload content
            currentSWFLoader = swf2;
            currentSWFLoader.load();
        }
    }
}


bar.scaleX = 0;
currentSWFLoader.load();
 

 

 

Link to comment
Share on other sites

Sorry, but our support of AS3 is pretty much non-existent as their is virtually no market demand. 

 

 

 

For this very simple case you are using you may just add another conditional statement that checks to see if the 2nd swf is done playing just like the code is doing for the first

 

 

if (currentSWFLoader == swf2) {
            currentSWFLoader.dispose(true) // dispose and unload content
            currentSWFLoader = swf1;
            currentSWFLoader.load();
        }

Perhaps this will help. There is most likely a much more flexible solution that would handle multiple swfs. Unfortunately we just can't afford to spend the time on these things. 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...