AllenSeattle
02-01-2008, 10:06 PM
Hi I recently found a great tutorial on loading external swf files using an array to load. I realized that there wasn't a heck of a lot of examples online for complex classes, but this is a good site (www.flashandmath.com) !
Anyway...
I began to develop my own move loader, but want to expand the math portion of the button function that allows the user to jump through the array. What I would like to have is another button that will go the opposite direction through the array, thus display previous movies. Each loaded movie is a simple animated clip.
Unfortunately, I am a designer, and have never used flash for heavy coding.
I am aware of how much I am missing, but would like to at least see how it is done so that I can scratch my head some more. If anyone has a way to make this work, it would be much appreciated! Thanks in advance!
Here is my code:
/*
This file comes from www.flashandmath.com
*/
// Array of external clips to use. Variable index refers to next clip to be displayed.
var clips:Array = ["clip0.swf", "clip1.swf", "clip2.swf"];
var index:int = 0;
// Stuff to load swf files
var thisLoader:Loader = new Loader();
thisLoader.contentLoaderInfo.addEventListener(Even t.INIT, doneLoading);
var thisMC:MovieClip = new MovieClip();
stage.addChild(thisMC); // Add empty MC initially so the nextClip function can be generic
// Removes old MC and gets the next one, waiting until when it has initialized beore adding it to the stage
function nextClip():void {
thisLoader.load(new URLRequest(clips[index]));
}
/*I added this function to try to reverse the order of the array being displayed*/
function prevClip():void {
thisLoader.load(new URLRequest(clips[index]));
}
// Tell AS that the loaded file is a movie clip and add it to the stage.
function doneLoading(e:Event):void {
stage.removeChild(thisMC);
thisMC = MovieClip(thisLoader.content);
thisLoader.unload();
stage.addChild(thisMC);
thisMC.play();
}
// "Next button" just calls a function that goes to the next file name (mod the number of files in the list)
btnNext.addEventListener(MouseEvent.CLICK, playNext);
function playNext(e:MouseEvent):void {
nextClip();
index = (index + 1)%(clips.length);
}
/*I added this button event and function to try to reverse the order of the array being displayed*/
btnPrev.addEventListener(MouseEvent.CLICK, playPrev);
function playPrev(e:MouseEvent):void {
prevClip();
if(index > 0){
clips.reverse();
index = (index + 1)%(clips.length)
}
}
Anyway...
I began to develop my own move loader, but want to expand the math portion of the button function that allows the user to jump through the array. What I would like to have is another button that will go the opposite direction through the array, thus display previous movies. Each loaded movie is a simple animated clip.
Unfortunately, I am a designer, and have never used flash for heavy coding.
I am aware of how much I am missing, but would like to at least see how it is done so that I can scratch my head some more. If anyone has a way to make this work, it would be much appreciated! Thanks in advance!
Here is my code:
/*
This file comes from www.flashandmath.com
*/
// Array of external clips to use. Variable index refers to next clip to be displayed.
var clips:Array = ["clip0.swf", "clip1.swf", "clip2.swf"];
var index:int = 0;
// Stuff to load swf files
var thisLoader:Loader = new Loader();
thisLoader.contentLoaderInfo.addEventListener(Even t.INIT, doneLoading);
var thisMC:MovieClip = new MovieClip();
stage.addChild(thisMC); // Add empty MC initially so the nextClip function can be generic
// Removes old MC and gets the next one, waiting until when it has initialized beore adding it to the stage
function nextClip():void {
thisLoader.load(new URLRequest(clips[index]));
}
/*I added this function to try to reverse the order of the array being displayed*/
function prevClip():void {
thisLoader.load(new URLRequest(clips[index]));
}
// Tell AS that the loaded file is a movie clip and add it to the stage.
function doneLoading(e:Event):void {
stage.removeChild(thisMC);
thisMC = MovieClip(thisLoader.content);
thisLoader.unload();
stage.addChild(thisMC);
thisMC.play();
}
// "Next button" just calls a function that goes to the next file name (mod the number of files in the list)
btnNext.addEventListener(MouseEvent.CLICK, playNext);
function playNext(e:MouseEvent):void {
nextClip();
index = (index + 1)%(clips.length);
}
/*I added this button event and function to try to reverse the order of the array being displayed*/
btnPrev.addEventListener(MouseEvent.CLICK, playPrev);
function playPrev(e:MouseEvent):void {
prevClip();
if(index > 0){
clips.reverse();
index = (index + 1)%(clips.length)
}
}