Actions to occur after onLoadInit is checked

Hi there,

I have a problem with some code. Its in the else statement below. Essentially I am trying to make sure I can read in the mc._height value before I continue with the code, I use a listener to check that I can get the value which I can,however it seems to do all the code after the loadListner.onLoadInit function before this function. Any help would be greatly appreciated!!
function displayAll() {
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_position = i;
if (inBead.bead_loc == undefined) {
removeMovieClip("_root.mySlider.undefined");
} else {
var loadListener:Object = new Object();
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(“width”+mc._width);
trace(“height”+mc._height);
};
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“mc”, this.getNextHighestDepth());
mcLoader.loadClip(inBead.bead_loc, mc);
inBead._x = currentPosition;
currentPosition = (currentPosition+Number(band*[3]));
inBead._y = composite_start_pos_y+inBead._height/2;
}
}
_global.spaceTotal = currentPosition-composite_start_pos_x;
formatDecimals(total, digits);
total_price.text = (“Total Price £”+newTotal);
}

Your listener is created within the else statement, so when the else statement is triggered the listener is created and and listens for when the swf is loaded and ready to be accessed. This may not happen right away as it depends on the size of the swf or movieclip. Once the listener is created the code still moves on, so it is natural that the functions outside the onLoadInit function would fire before the listener code as the listener will only fire once the swf/movieclip is fully loaded and ready to be accessed and all other code falls outside of this but still in the else statement. If you want to prevent all other code from firing you can do 2 things. You can nest all the code inside the listener function under the trace statements, as this will not allow it to run until the listener function has been called. Or you could create an error checking function or variable to check for when the swf is ready and the fire the remaining functions. I have included both ways below: All changed code is bold.

Putting all code within the listener function
} else {
var loadListener:Object = new Object();
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(“width”+mc._width);
trace(“height”+mc._height);
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“mc”, this.getNextHighestDepth());
mcLoader.loadClip(inBead.bead_loc, mc);
inBead._x = currentPosition;
currentPosition = (currentPosition+Number(band*[3]));
inBead._y = composite_start_pos_y+inBead._height/2;
}
}
}
**
Creating error checking**
var swfIsReady:Boolean = false
} else {
var loadListener:Object = new Object();
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(“width”+mc._width);
trace(“height”+mc._height);
swfIsReady = true;
};
}
}
onEnterFrame = function() {
if(swfIsReady){
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider[stripX2(band
[0])+i].createEmptyMovieClip(“mc”, this.getNextHighestDepth());
mcLoader.loadClip(inBead.bead_loc, mc);
inBead._x = currentPosition;
currentPosition = (currentPosition+Number(band
[3]));
inBead._y = composite_start_pos_y+inBead._height/2;
}else {
trace(“swf has not been fully initialized”);
}
}**

Many thanks for your reply.

Unfortunately I it causes a bit of a problem. This function is inside a loop, because I am generating many movieclips and essentially I want to be able to ge the height. Even if I put everything within the loadListener function, my generated movie clips do not appear, can you habe the loadClip inside the listener function.

Also I can’t access the value of mc._height anywhere outside the loadListener function. Any ideas? Please let me know if any of this is unclear

Many Thanks

var loadListener:Object = new Object();

trace(“start”);
loadListener.onLoadInit = function(mc:MovieClip):Void {
trace(“middle”);
trace(“width”+mc._width);
trace(“height”+mc._height);
_global.heightSize = mc._height;
inBead.btn_drag._height = _global.heightSize;
inBead.btn_drag._width = mc._width;
inBead._height = _global.heightSize;
trace(mc._height);
trace(inBead.btn_drag._height);
trace(_global.heightSize);
trace(inBead._y);
trace(inBead._x);
inBead._x = currentPosition;
inBead._y = composite_start_pos_y;

};

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“mc”, this.getNextHighestDepth());
mcLoader.loadClip(inBead.bead_loc, mc);

 currentPosition = (currentPosition+Number(band*[3]));

trace(“end”+mc._height);
}

Just to add, when I trace “start” “middle” and “end”. I want the traces to appear in that order, but it always returns start, end then middle. If I put the 4 lines of code about creating the movieclip loader etc inside the loadListener.onLoadInit = function. The function doesn’t run at all.

var loadListener:Object = new Object();

trace(“start”);
loadListener.onLoadInit = function(mc:MovieClip):Void {
trace(“middle”);
trace(“width”+mc._width);
trace(“height”+mc._height);
_global.heightSize = mc._height;
inBead.btn_drag._height = _global.heightSize;
inBead.btn_drag._width = mc._width;
inBead._height = _global.heightSize;
trace(mc._height);
trace(inBead.btn_drag._height);
trace(_global.heightSize);
inBead._x = currentPosition;
inBead._y = composite_start_pos_y;
trace(inBead._y);
trace(inBead._x);
};

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“mc”, this.getNextHighestDepth());
mcLoader.loadClip(inBead.bead_loc, mc);

currentPosition = (currentPosition+Number(band*[3]));
trace(“end”);
}