Help! Passing variables between functions

Hi there,

I have been searching for what seems like weeks for an answer to this question, here is my problem:

I am building a flash photo gallery that is fed by an XML file, now I am fine with all of the XML things in flash, my problem comes when creating the thumbnail images onRelease event. Here is my code:


_global.counter = 0;

for (_global.counter = 0; _global.counter<itemArray.length; _global.counter++) {
        //populate thumbnail array with URLS
        thumbnails[_global.counter] = itemArray[_global.counter].childNodes[10].attributes.url;
        //Populate images array with URLS
        images[_global.counter] = itemArray[_global.counter].childNodes[7].attributes.url;
        //Generate an empty movieClip for each thumbnail
        grid_container_mc.attachMovie("thumbHolderID","thumb_"+_global.counter+"_mc",_global.counter);
        //load in the thumbnail ur to the newly created movieClips
        //grid_container_mc["thumb_"+_global.counter+"_mc"].loadMovie(thumbnails[_global.counter]);
        //Set the _x & _y coordinates for the newly created movieclips
        grid_container_mc["thumb_"+_global.counter+"_mc"]._x = ((_global.counter % 3)* xSpace);
        grid_container_mc["thumb_"+_global.counter+"_mc"]._y = ((Math.floor(_global.counter/3)*ySpace));
        //scale the thumbs
        grid_container_mc["thumb_"+_global.counter+"_mc"]._xscale = scaleRatio;
        grid_container_mc["thumb_"+_global.counter+"_mc"]._yscale = scaleRatio;
            
        
        //create the onRelease events for the thumbs
        grid_container_mc["thumb_"+_global.counter+"_mc"].onRelease = function(){
            image_holder_mc.loadMovie(images[_global.counter]);
        }
    }

The problem is that when I release the mouse button I get a variable undefined error in the output window. I have researched and have found that my problem is that I can’t pass a variable from the main function to the onRelease function, but am stumped as to how to get around this!

Any help any of you can give would be fantastic! This needs to be finished in a hurry and I am getting desperate…

I know its bad form to just use a forum to ask for help but I dont know what else to do!

Thanks!