I have a code that loads 4 swf files into main swf file one after another , but unfortunately I faced 2 problems : here is my code :
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
progress_mc.scaleX = 0;
var loaderIndex:Number = -1;
var currentLoader:SWFLoader;
var swfs:LoaderMax = new
LoaderMax({onComplete:completeHandler,onProgress:progressHandler,onChildComplete:childCompleteHandler});
swfs.append(new SWFLoader("part1.swf", {container:container_mc, autoPlay:false}));
swfs.append(new SWFLoader("part2.swf", {container:container_mc, autoPlay:false}));
swfs.append(new SWFLoader("part3.swf", {container:container_mc, autoPlay:false}));
swfs.append(new SWFLoader("part4.swf", {container:container_mc, autoPlay:false}));
function progressHandler(e:LoaderEvent):void {
progress_mc.scaleX = e.target.progress;
}
function childCompleteHandler(e:LoaderEvent):void {
trace(e.target + " loaded");
e.target.content.visible = false;
}
function completeHandler(e:LoaderEvent):void {
trace("all swfs loaded");
progress_mc.visible = false;
initCurrentLoader();
addEventListener(Event.ENTER_FRAME, trackSWFPlayback);
}
function initCurrentLoader() {
loaderIndex++;
if (loaderIndex == swfs.numChildren) {
//reset back to 0 if the last swf has already played
loaderIndex = 0;
}
//dynamically reference current loader based on value of loaderIndex
currentLoader = swfs.getChildAt(loaderIndex);
//make the content of the current loader visible
currentLoader.content.visible = true;
//tell the current loader's swf to to play
currentLoader.rawContent.gotoAndPlay(1);
}
function trackSWFPlayback(e:Event):void {
//trace(currentLoader.rawContent.currentFrame);
//detect if the loaded swf is on the last frame
if (currentLoader.rawContent.currentFrame == currentLoader.rawContent.totalFrames) {
trace("swf done");
//hide and stop current swf
currentLoader.content.visible = false;
currentLoader.rawContent.stop();
//set up and play the next swf
initCurrentLoader();
}
}
load_btn.addEventListener(MouseEvent.CLICK, loadSWFs)
function loadSWFs(e:MouseEvent):void{
load_btn.visible = false;
swfs.load();
}
problem 1 : part1.swf that is a swf file not made with adobe flash does't load. here is the error I can see each time :
RangeError: Error #2006: The supplied index is out of bounds. at flash.display::DisplayObjectContainer/getChildAt() at dblogo() at flash.display::Sprite/constructChildren() at flash.display::Sprite() at flash.display::MovieClip() at dbmovie() SWFLoader 'loader2' (part2.swf) loaded SWFLoader 'loader1' (part1.swf) loaded SWFLoader 'loader4' (part4.swf) loaded SWFLoader 'loader3' (part3.swf) loaded all swfs loaded swf done
poblem 2 : I have a line in my script that stops last swf . as I want to load swf files that maybe huge I rather that to unload instead of just stoping swfs . how to unload each swf instead of stoping it . as I'm completely new to flash and as3 can every one simply edit my as3 to fix these two main problems . Any Any Any Suggestions are EXTREMELY appreciated...Thanks a lot