Keeping a variable unique for a dynamically created function

**Hi guys,

Sorry if this is addressed elsewhere, I’ve been scouring the internet for over an hour but I’m not entirely sure even what to search for exactly.

What I’m trying to do is setup a function that shoots through a set of buttons within a subset and creates click code for these buttons.

THe three variables are the identifiers for the actual keyframe i wish to jump to, the movieclip in which i want to perform the action and the actual button to go to the right frame.

Presently the problem I’m having is that the variables aren’t stored when the onRelease functions are created, so they all are just calling the LAST variables declared.

Here’s a sample of the code I currently have


//function to load canvas/acrylic
function setSwatches(mySwatchCount:Number, myContainer:String)
{
    //set holder name
    var myContainerName = myContainer + "_mc"
    
    //cycle for each swatch
    for(var i = 0; i < mySwatchCount; i++){
        var mySwatchbtn = myContainer+ "_" + i + "_btn";
        var myFrameLabel = "a"+i; //adds an "a" because frame labels don't work with numbers

        //attach button code to load each swatch
        trace(myFrameLabel);
        
        this[mySwatchbtn].onRelease = function(){
            trace(myFrameLabel);
            _root[myContainerName].gotoAndStop(myFrameLabel);
        }
    }
}

//setup buttons
setSwatches(8, "fa_acrylic");
setSwatches(8, "fa_canvas");

Thanks guys!
Steve
Natural Cow Design
http://www.naturalcowdesign.com.au
**