Such a simple thing, so much trouble

Hi there everyone,

I’m still pretty much a novice when it comes to actionscript and I hope someone can point out where I’m going wrong with my script here. All I’ve been trying to do these last few days is make a simple xml image viewer with one little extra feature which I thought would be easy enough to figure out. The images are of different sizes, and I would like to have it so that when you click the ‘next’ and ‘previous’ buttons, the current image shrinks or expands to match the size of the next or previous one, while at the same time fading out. I thought the best way to start doing this would be to load the images one by one into an empty mc, push their widths and heights into arrays, and then reload all of the images in their own separate mc’s which I would then manipulate with Tweens. But I’m jiggered before I can get that far. Extracting the dimensions of each imgae seems to work alright, but the part where I create the empty movie clips and try to load the pictures into them one by one (see loadAllPics function) just won’t work at all. The whole friggin’ movie is replaced by the first image.

Please, someone help. :slight_smile:


// this empty movie clip will hold the images
// as the width and height are extracted
this.createEmptyMovieClip("tempHolder_mc", -100);
// this empty movie clip will hold the 
// empty movie clips into which each
// image will eventually be loaded
this.createEmptyMovieClip("container_mc", -5);
// These variables are used as counters in some of the functions.
var i:Number = 0;
var k:Number = 0;
var m:Number = 0;
// This array will store the names of the pictures.
var pic_array:Array = new Array();
// These arrays will store the height and width of each picture.
var w_array:Array = new Array();
var h_array:Array = new Array();
// creates movie clip loader
var mcLoader:MovieClipLoader = new MovieClipLoader();
// This listener object will listen for movieclips loaded with mcLoader.
var Listener:Object = new Object();
mcLoader.addListener(Listener);
// When parseX() has finished populating pics_array, this 
// function loads each jpeg into tempHolder_mc while
// storing its width and height in w_array and h_array.
function loadPic() {
    mcLoader.loadClip(pic_array*, tempHolder_mc);
    Listener.onLoadInit = function(target_mc:MovieClip) {
        if (i<pic_array.length) {
            trace(i);
            w_array.push(target_mc._width);
            h_array.push(target_mc._height);
            trace("width: "+w_array*);
            trace("height: "+h_array*);
            unloadMovie(target_mc);
            i++;
            if (i == pic_array.length) {
                createAllEmpties();
                return;
            } else {
                loadPic();
            }
        }
    };
}
// This function is called when the xml has finished loading.
// It populates pic_array nd then triggers loadPic(). 
function parseX() {
    trace("XML loaded successfully");
    for (j=0; j<xViewer.firstChild.childNodes.length; j++) {
        pic_array.push(xViewer.firstChild.childNodes[j].attributes.picture);
    }
    if (pic_array.length == xViewer.firstChild.childNodes.length) {
        trace("pic_array: "+pic_array);
        loadPic();
    }
}
//
// This function creates empty movie clip into 
// which each image will be loaded
function createAllEmpties() {
    if (k>=pic_array.length) {
        loadAllPics();
        return;
    }
    if (k<pic_array.length) {
        container_mc.attachMovie("mcEmpty", "mcEmpty"+k, k);
        k++;
        createAllEmpties();
    }
}
// This is the function that does not work...
function loadAllPics() {
    if (m == pic_array.length) {
        return;
    }
    if (m<pic_array.length) {
        mcLoader.loadClip(pic_array[m], mcEmpty+m);
        Listener.onLoadInit = function(target2_mc:MovieClip) {
            m++;
            loadAllPics();
        };
    }
}
// Creates XML object. The names of the imgages to be
// loaded are found in the external xml file "viewer.xml".
var xViewer:XML = new XML();
xViewer.ignoreWhite = true;
xViewer.onLoad = function(success) {
    if (success && this.status == 0) {
        parseX();
    }
};
xViewer.load("viewer.xml");

Fingers