I'm having scope problems in onMotionFinished when I set a bunch of tweens in a for loop:
(AS2)
for (var i:Number=0; i<navSectionArray.length; i++){
var scope:MovieClip = mcNav["mc"+navSectionArray[i]];
if (navSectionArray[i] == selectedNav){
// selected
this["bgTween"+i] = new Tween(scope.mcBG, "_width", Strong.easeOut, scope.mcBG._width, 100, .5, true);
this["bgTween"+i].onMotionFinished = function(){
trace ("open: "+scope);
};
} else {
// others
this["bgTween"+i] = new Tween(scope.mcBG, "_width", Strong.easeOut, scope.mcBG._width, 1, .5, true);
this["bgTween"+i].onMotionFinished = function(){
trace ("close: "+scope);
};
}
}
The problem, obviously, is that they ALL trace the same scope, because the for loop has completed before any of the onMotionFinished functions have fired. I can't figure out how to be able to pass a target or a var or something through to the onMotionFinished function(s) that will persist until those functions actually fire.
Is there a way in onMotionFinished to get the target of the original tween?