onLoad Init function in a for loop

Hi all,

I’m having real trouble getting the onLoadInit function to work inside a for loop

Essentially I am looping through multiple dynamically created movieclips.

When the movieclip is loaded, I want to check that it has loaded using onLoadInit, because I need the height and width values for the next part.

I’ve written the traces first, second and third (there sare the order in which I want things to occur)

When I run the code it always traces back first, third, second!)

I need to find a way for it to complete the onLoadInit, during the loop before it carries on to the end of the loop.

The code is below, and help would be greatly appreciated!

Thanks

function displayAll() {
total_price.text = (“Total Price £”+total);
_global.spaceTotal = 0;
var inBead:MovieClip;
currentPosition = composite_start_pos_x;
for (var i = 0; i<=beadsOnComposite; i++) {
inBead = _root.mySlider.attachMovie(“inside_bead_object”, stripX2(band*[0])+i, i);
inBead.bead_name = band*[0];
inBead.bead_price = band*[1];
inBead.bead_loc = band*[2];
inBead.bead_size = band*[3];
inBead.bead_id = band*[4];
inBead.bead_height = band*[5];
inBead.bead_specialHeight = band*[6];
inBead.bead_position = i;
if (inBead.bead_loc == undefined) {
// if this is undefined it means the entry has been deleted, so don’t rebuild a visible object
removeMovieClip("_root.mySlider.undefined");
} else {
inBead._x = -50;
inBead._y = -50;
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var screen:MovieClip = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“screen”, i);
mcLoader.loadClip(inBead.bead_loc, screen);
trace(“FIRST”)
var loadListener:Object = new Object();
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(“SECOND”)
_root.mySlider[stripX2(band*[0])+i]._y = composite_start_pos_y-Number(_root.mySlider[stripX2(band*[0])+i]._height/2);
_root.mySlider[stripX2(band*[0])+i]._x = currentPosition;
_global.spaceTotal = _root.mySlider[stripX2(band*[0])+i]._x;
currentPosition += band*[3];
};
}
}
trace(“THIRD”+currentPosition);
formatDecimals(total, digits);
total_price.text = (“Total Price £”+newTotal);
_global.spaceTotal = currentPosition-composite_start_pos_x;
}