Hello Flash folk,
Rather stumped here.
Below is a pseudo class that displays an array of dynamically loaded
jpegs. I need to arrange them next to each other, and since their widths
are all different, I am using MovieClipLoader and the onLoadInit event to
get the width and height of the jpeg only after it's loaded. I write these
measurements to an array. So far so good.

My problem comes when trying to read this array: it's empty!
My guess is that the array goes out of scope with the onLoadEvent of the
listener.

Hopefully someone will have some ideas to help me push this rock a little
bit further up the hill.

Thanks!
Daniel.

_global.PhotoAlbum = function(photos_arr:Array) {
        this.holders = new Array();//holds movie clips
        this.dims = new Array();//i want to put widths and heights here

        //methods
        this.displayAlbum = function(Void) {
                var ref = this;//used within listener event
                var loader = new MovieClipLoader();
                var listener = new Object();

                //event handler to get width and height of loaded jpeg
                listener.onLoadInit = function(holder:MovieClip):Void {
                                ref.setDims(holder._width, holder._height);
                }
                loader.addListener(listener);
                for (locIndex in this.photos) {
                        var mc:String = "mc" + locIndex;
                        var holder:MovieClip = createEmptyMovieClip(mc, 
getNextHighestDepth());
                        loader.loadClip(this.photos[locIndex], holder);
                        holder._lockroot = TRUE;
                        this.holders.push(holder);
                }
                this.arrangePictures(this.holders);
                trace (this.dims.length) //returns 0 :(
        };

        //helper methods
        this.setDims = function(w:Number, h:Number) {
                this.dims.push(w);
                this.dims.push(h);
                trace (this.dims); //works okay! but only within this scope
        };
        this.arrangePictures = function(holders:Array) {
                trace (this.dims.length) //returns 0 :(
//my goal is to retrieve the widths and heights set by this.setDims,
//but the this.dims array is empty at this point.
//maybe something wrong with the scope?
        };
};
//I call it like this:
photos_arr = ["pic1.jpg","pic2.jpg","pic3.jpg"];
album = new PhotoAlbum (photos_arr);
album.displayAlbum();

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to