views:

345

answers:

2

how to load a movie[.swf] at the end of another movie[.swf] in AS3?

thanks

+1  A: 

The easiest way is to do something like this on the last frame of your movie clip:

var myLoader:Loader = new Loader(); 
addChild(myLoader); 
var url:URLRequest = new URLRequest("myExternalMovie.swf"); 
myLoader.load(url); 

But the best way is to use something like this to listen for the end of the last movie clip:

if (mc1.currentFrame == mc1.totalFrames) {
 //code to load next movie clip
}

Use the currentFrame and totalFrames to find if the first clip is done playing.

Use this to create a MovieClip Instance:

var mc:MovieClip = new MovieClip();
//properties code here (just his .)
addChild(mc);
Todd Moses
what is mc1? i have not got any movie clips in the library,do i have to create instances?sorry with all the questions,im new to AS.
manraj82
You have to create an instance of a Movie Clip (mc1 in the example) and then you will have access to its properties. See: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html for more help on Movie Clip.
Todd Moses
var myLoader:Loader = new Loader(); mc1.addChild(myLoader); var url:URLRequest = new URLRequest("movie1.swf"); myLoader.load(url); if (mc1.currentFrame == mc1.totalFrames) { trace("end of movie 1");}the above code displayed the message on frame 1,even thought it has 100 frmaes.any ideas why?
manraj82
mc1 is not a MovieClip it is your stage. Do not use the above example of a Loader. Instead just add a MovieClip to the stage then load the SWF into it with the loader.
Todd Moses
@todd: this is what i have done,i have got a main FLA called main.flathen created a movie clip with an instance mc1 and placed it on the stage.then i wrote the above code on the first frame of the main.fla.
manraj82
do not addChild to the movie clip. When you do the SWF is the child but the current and total frames for the new Movie Clip is 1.
Todd Moses
@todd: thanx 4 ur help,im sure you code will work but i got some code that did the job 4 me,had to tweak a bit though...thanks nyway
manraj82
A: 

here is a piece of code which i got when i googled around,and it works. i havnt got the guy's name but he saved the day 4 me

// Array of external clips to use. Variable index refers to next clip to be displayed.

var clips:Array = ["check.swf","02.swf"]; var index:int = 0;

// Stuff for loading files var thisLoader:Loader = new Loader(); thisLoader.contentLoaderInfo.addEventListener(Event.INIT, doneLoading);

var thisMC:MovieClip = new MovieClip(); stage.addChild(thisMC); // Add empty MC initially so the nextClip function works even on first call

// Gets the next MC, waiting for INITialization before adding it to the stage

function nextClip():void { thisLoader.load( new URLRequest(clips[index]) ); }

// Remove old clip, tell AS that the loaded file is the new one, add it to the stage, and play. function doneLoading(e:Event):void { stage.removeChild(thisMC); thisMC = MovieClip(thisLoader.content); thisLoader.unload(); thisMC.addEventListener(Event.ENTER_FRAME, runOnce); stage.addChild(thisMC); thisMC.gotoAndPlay(1); }

// When currentFrame equals totalFrames in loaded clip (playing), increment index & play the next clip. function runOnce(e:Event):void { if (thisMC.currentFrame == thisMC.totalFrames) { thisMC.removeEventListener(Event.ENTER_FRAME, runOnce); index = (index + 1)%(clips.length); nextClip(); } }

// Call nextClip to automatically start the first clip

nextClip();

manraj82