Background:
I'm creating a scrolling function that will scroll a dynamic list of images. I am putting all content into MovieClip container that will then scroll. The images are being loaded via XML but there is no height or width passed from the XML spec. I must detect the height and width post load.
The Problem:
The container name is "image_mc" (see attached code). The "height" attribute needs to be updated by the total height of the loaded images in the stack. This of course needs to happen after all files have been loaded. I must be missing something. Any help is appreciated. I simplified the code for clarity.
The Question:
How do I pass a variable from within "onLoadInit" to update a MovieClip's height? I can pass variable into "onLoadInit" just fine but getting a variable out has been a pain.
ActionScript Code:
/*
* ImageLoaderScope.as
* Place "ImageLoaderScope.main(this);" in the root of your FLA doc.
* Put any image in the "image_url[i]" variable.
*/
class ImageLoaderScope {
private var image_clip:Array = [];
private var image_url:Array = [];
public function ImageLoaderScope(target:MovieClip){
build(target);
}
public function build(target:MovieClip) {
var thisMC = this;
var app = { stack_x: 50, stack_y: 50 };
// This "height" needs to be updated by the total height of the loaded images in the stack.
var image_mc:MovieClip = createRectangle(350, 200, 0x000000, target);
for (var i = 0; i < 3; i++) {
image_url[i] = "bacon.jpg";
image_clip[i] = image_mc.createEmptyMovieClip("image_clip" + i, image_mc.getNextHighestDepth());
var mc_listener:Object = new Object();
mc_listener.onLoadInit = function(target_mc:MovieClip) {
target_mc._x = app.stack_x;
target_mc._y = app.stack_y;
app.stack_y = app.stack_y + target_mc._height;
app.image_mc._height = app.stack_y;
}
mc_listener.onLoadStart = function(target_mc:MovieClip) {
}
mc_listener.onLoadComplete = function(target_mc:MovieClip) {
}
var mc_loader:MovieClipLoader = new MovieClipLoader();
mc_loader.addListener(mc_listener);
mc_loader.loadClip(image_url[i], image_clip[i]);
}
}
public function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.beginFill(color);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);
return mc;
}
public static function main(target:MovieClip){
var player:ImageLoaderScope = new ImageLoaderScope(target);
}
}
Attachment 499