Saturday, 5 December 2009

Enumerate through loaded swfs in AS3

I received a question from the load external swf tutorial about how to enumerate or loop through an array of external swfs in Actionscript 3. Below is my solution. I have used the shorten if-else statement in the both the forward and back functions to increment and decrement the array index. When the index has reached the end of the array, the index gets reset to zero. And when index has reached the beginning of the array, index get set to the end of the array.

var clips:Array = ["box.swf", "content1.swf", "white.swf"];
var index:int = 0;

var myLoader:Loader=new Loader();
myLoader.load(new URLRequest(clips[index]));

advance_btn.addEventListener(MouseEvent.CLICK, forward);
back_btn.addEventListener(MouseEvent.CLICK, back);

function forward(event:MouseEvent):void {

index == arr.length-1 ? index = 0 : index++;
myLoader.load(new URLRequest(clips[index]));


function back(event:MouseEvent):void {

index == 0 ? index = arr.length-1 : index--; 
myLoader.load( new URLRequest(clips[index]) );



dramaqueen 24 July 2013 at 20:36  

Hi, How can I modify your code above so the swf play after once another without clicking the button?

iliketo 29 July 2013 at 13:57  


In the external swfs you will need to write some code to notify when it has finished playing. You could call a function from the external swf to load the next swf.

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP