I’m working with code to sequentially load .swf files. I’m using the code below with some success except I’m getting a flicker during the loading of about the first half of the first movie. That is the second movie load flickers in a few frames on and off. Then it “settles” down and all is well. I suppose it has to do with the initial loading because the problem is consistant with all different .swf file loads and always “settles” at the same point. I thought that a preloader might fix this but I didn’t succeed. Any thoughts?
One other challenge for me is that this code continues back to the first .swf file and then stops. Not sure why.
The code is below.
If you want to check out the file problem the address is:
http://cardandcardbeta.com/castletour/castle_tour.html
Thanks, Phil
//var my_loader:Loader = new Loader();
//my_loader.load(new URLRequest(“water.swf”));
//addChild(my_loader);
// Sets up a counter to keep track of the swf index (one each for loading and playback)
var currentPlaySwf:Number = 0;
var currentLoadSwf:Number = 0;
// Sets up an array that contains all the swfs to be loaded - ORDER IS VERY IMPORTANT
var swfs:Array = new Array(“mov1.swf”, “mov2.swf”, “mov3.swf”, “mov4.swf”);
// Sets up an array of MCs that will load and contain the SWFs. This is generated dynamically.
var swfHolders:Array = new Array();
for (var i:Number = 0; i < swfs.length; i++) {
swfHolders.push(this.createEmptyMovieClip(“swfHolder”+i, this.getNextHighestDepth()));
}
// Since we’re only going to load one SWF at a time, we only need one MCL. I’m also going to use
// “this” as the listener, instead of another object. This just means that a function called
// “onLoadInit” will get called by the MCL.
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(this);
function onLoadInit(target:MovieClip):Void {
// This is just a check to see if we’re on the first SWF or not.
// If we are, start playing. If not, hide and prevent playback.
if (currentLoadSwf == 0) {
target._visible = true;
} else {
target._visible = false;
target.stop();
}
// Increment the load counter and load the next SWF (this will prioritize the load to one-at-a-time,
// with the first SWFs up front).
currentLoadSwf++;
startLoading()
// Now, set up the enter frame listener to detect the last frame
target.onEnterFrame = function():Void {
if (this._currentframe == this._totalframes) {
// Once on the last frame, increment the play counter
currentPlaySwf++
// If the counter ever exceeds the available items in the Array, loop back around to the start.
if (currentPlaySwf >= swfHolders.length) {
currentPlaySwf = 0;
}
// Set the visible of the next holder MC to true and start playing.
swfHolders[currentPlaySwf]._visible = true;
swfHolders[currentPlaySwf].play();
// Always make sure that this SWF stops playing and stops executing this code every frame.
this.stop();
this._visible = false;
delete this.onEnterFrame;
}
}
}
// Starts loading the currentSwf. This gets called once manually, to start everything, and then
// automatically thereafter from the onLoadInit.
function startLoading():Void {
mcl.loadClip(swfs[currentLoadSwf], swfHolders[currentLoadSwf]);
}
// Load the first one.
startLoading();