PDA

View Full Version : Waiting for an object to finish before continuing for statement


KyleHarrison
11-14-2007, 02:23 AM
So what im trying to do is create an engine that runs through an xml file and grabs the data, puts it into an array, passes the array into a function and so on and so fourth.

Everythings going fine until i hit a roadblock.

var playGame = function():Void {
log("---- Start Game ----");
for(l=0;l<structure.length;l++) {
var blockArray = structure[l].split("|");
log("blockArray = " + blockArray);
switch(blockArray[0]) {
case "movie":
log("This is a Movie");
playMovie(blockArray[1],blockArray[2],blockArray[3]);
break;
case "map":
log("This is a Map");
playMap(blockArray[1],blockArray[2],blockArray[3]);
break;
case "menu":
log("This is a menu");
playMenu(blockArray[1],blockArray[2],blockArray[3]);
break;
default:
break;
}
}
}
var playMovie = function(id,src,name):Void {
// Cinema Playback

log("Src = " + src);
var cLoader:MovieClipLoader = new MovieClipLoader();
this.createEmptyMovieClip("cContainer", this.getDepth(consoleBG)-1);
cLoader.loadClip(src, cContainer);
//_global.inProgress=true;
_global.inProgress = true;
while(inProgress == true) {
// this infinite loop crashes the game
}
}
var finished = function() {
_global.inProgress = false;
}

theres the code that matters most

Essentially what im trying to accomplish, is its loading an external SWF movie and i want it to wait until its done, before executing the next object in the array (which is a level).

In the SWF object, i have
_parent.finished();

being called which is to tell the engine that its done and can continue on with the next object.

im assuming id use a this.onEnterFrame but i havent a clue where, and an infinite while loop just crashes the engine (obviously)

im at my wits end, does anybody have an idea here?

kool-Aid
11-18-2007, 08:43 PM
//will something like this work. you will have to plug in your instance names and stuff but here is an idea.

var amount:Number = your_loader.getBytesLoaded() / your_loader.getBytesTotal();
if(amount == 100) {
///put whatever you want next under this line
this.gotoAndPlay(whtever);
}


you would put this instead of you in progress and stuff