I am trying to make use of two ‘arrays’ in one ‘for’ loop. The two arrays are called ‘overlay’ and ‘button’. The contents of both arrays all refer to movieclip instances on the stage. What is happening is that the corresponding ‘overlay*’ button will perform the alpha change according to a rollover.
However, the state of the corresponding ‘button*’ will not respond and change its alpha state. I did a trace for ‘button*’ and ‘undefined’ is returned. I thought it might be a level referencing problem, so I made all the instances in the button array have ‘_root.’. but that didn’t solve the problem either.
The following is the for loop. Anyone have any suggestions?
for ( var i = 0; i < overlay.length; i++ ) {
overlay*.onRollOver = function () {
this._alpha = 50;
button*._alpha = 50;
trace (button*); // returns ‘undefined’
}
}
When the actual onRollOver happens, the for loop has already finished by far then, and the i variable is lost. So store it in a property during the loop so it can be retrieved later:
I would also do it as Voetsjoeba has explained but i don`t think you should use button as the name of an array and also if everything is on the same timeline you will have to reference it slightly differently
maybe
for (var i = 0; i<overlay.length; i++) {
overlay*.id = i;
overlay*.onRollOver = function() {
this._alpha = 50;
this._parent.buttonnewname[this.id]._alpha = 50;
trace(this._parent.buttonnewname[this.id]);
};
}