Action Script 2.0 for playing a loop of a series of SWF files defined in an array.

So, yeah. Say you want to create a SWF that imports a series of SWFs and loops them. Well, here’s one way to do this.

// Action Script 2.0 for playing a loop of a series of SWF files defined in an array.
// Completion of the individual SWFs is defined as the event when the current frame
// is equal to the total number of frames.

fscommand("FULLSCREEN","true");
fscommand("showmenu", "false");

// You'll need a movie clip on the stage named movies_mc to hang the SWFs from. If you decide not to have one you can uncomment the following line to generate one.
//this.createEmptyMovieClip("movies_mc", 1);
var main_mc:MovieClipLoader = new MovieClipLoader();

var mcListener:Object = new Object();
main_mc.addListener(mcListener);

var movieTitle:Array = ["movie1.swf", "movie2.swf", "movie3.swf", "movie4.swf", "movie5.swf"];
var i:Number = 0;
var ii:Number = 0;

mcListener.onLoadInit = function(target_mc:MovieClip) {
    target_mc.onEnterFrame = function() {
        if (this._currentframe >= this._totalframes) {
            trace("total frames = " + this._totalframes);

            i++;
            loadNextMovie(movieTitle[modFunction(i, movieTitle.length)]);
            delete this.onEnterFrame;
        } else {
            trace(target_mc._currentframe+" OF "+target_mc._totalframes);
        }
    }
}

function loadNextMovie(moviePath) {
    if (i>0){main_mc.unloadClip(movies_mc);}
    trace("loading movie:" + moviePath + ", i="+i);
    main_mc.loadClip(moviePath, movies_mc);
}

function modFunction(n:Number,b:Number):Number {
  //****** MOD FUNCTION
  // n = number to apply the mod function to. b = base of for the mod function
  var result:Number = new Number();
  result = n - b*(Math.floor(n/b));
  return result;
}

loadNextMovie(movieTitle[i]);

This script should be loaded into the first frame of a single frame FLA.


Posted: May 25th, 2009 | Author: | Filed under: Code Reference | Tags: , | No Comments »

Leave a Reply