jlizarraga
01-06-2009, 11:49 PM
Simple test case: http://redesign1.autofusion.com/main/flash/scroller_new_v3.swf
I'm trying to assign onRollOver, onRollOut, and onPress event listeners to an array of movie clips that are acting as buttons, like so:
var gTabs:Array = [this.tabsAll, this.tabsPickup, this.tabsSedan, this.tabsHatchback, this.tabsCoupe, this.tabsConvertible, this.tabsCrossover, this.tabsVan, this.tabsSUV, this.tabsMinivan];
function someFunction():Void {
for (var i=0; i<gTabs.length; i++) {
var oName = gTabs[i]._name;
gTabs[i].onRollOver = function():Void {
this.gotoAndStop(2);
};
gTabs[i].onRollOut = function():Void {
this.gotoAndStop(1);
};
gTabs[i].onPress = function():Void {
_root.test_txt.text = oName;
};
}
}
As you can see from the demo, each tab correctly receives its rollOver and rollOut listeners; highlighting on mouseover as they should.
Now click a tab. The name of the tab (for example, "tabsAll" or "tabsCoupe") is supposed to show up. Instead, no matter which tab you click, "tabsMinivan" shows up.
Can anyone point me in the right direction? Why does oName get overwritten, and how can I avoid this behavior?
I'm trying to assign onRollOver, onRollOut, and onPress event listeners to an array of movie clips that are acting as buttons, like so:
var gTabs:Array = [this.tabsAll, this.tabsPickup, this.tabsSedan, this.tabsHatchback, this.tabsCoupe, this.tabsConvertible, this.tabsCrossover, this.tabsVan, this.tabsSUV, this.tabsMinivan];
function someFunction():Void {
for (var i=0; i<gTabs.length; i++) {
var oName = gTabs[i]._name;
gTabs[i].onRollOver = function():Void {
this.gotoAndStop(2);
};
gTabs[i].onRollOut = function():Void {
this.gotoAndStop(1);
};
gTabs[i].onPress = function():Void {
_root.test_txt.text = oName;
};
}
}
As you can see from the demo, each tab correctly receives its rollOver and rollOut listeners; highlighting on mouseover as they should.
Now click a tab. The name of the tab (for example, "tabsAll" or "tabsCoupe") is supposed to show up. Instead, no matter which tab you click, "tabsMinivan" shows up.
Can anyone point me in the right direction? Why does oName get overwritten, and how can I avoid this behavior?