[Flash 8]

Edit: Wasn’t sure what to call it and forgot the title! Fixed. :blush:

I’m working on an animation that switches “drawers” in and out of the stage. I’ve got the dynamic pathing mostly figured out (saves lots of redundant code), and solved a pesky “undefined” value error. But I’m stuck.

The problem: The last value of the loop is the only value passed to the onRelease function created in the loop. It identifies the last item in the (predefined) cabGen array (as shown below: “introduction”). I have changed the last item to test this and sure enough that is the variable assigned to every onRelease instance.

Sound familiar? :slight_smile: I know the solution is definitely here, in the kirupa.com FAQ. But I’m hitting a wall in applying it. Maybe I’ve been staring too long at this code!

var cabGen:Array = ["navigation","artstores","specificcats","generalcats","bigmap","credits","introduction"];
// ...
var i:Number;
for (i = 0; i < cabGen.length; i++) {
    var cabGenFix:String = cabGen*; // because you can't call cabGen* in a loop that uses it
    cabGenFix.index = i;
    this["cb_navigation"]["sw_" + cabGen*].onRelease = function() {
        cabOld = cabCurrent;
        cabCurrent = cabGen[cabGenFix.index];
    }
}

(note: other variables cabOld/cabCurrent are properly initialized)

I’m deeply appreciative for any insight on this one.