Hi, I can't get this For loop with onRollOver to work.
for (var i:Number = 1; i<=4; i++) {
this['videobutton'+i].onRollOver = function() {
trace(i);
this['stream'+i].pause(false);
this['video'+i].attachVideo(this['stream'+i]);
fadeIn(this['video'+i]);
};
}
It think it has to do with variable scope and the i, but I don't know how to fix it.
The trace gives me: 5
Any ideas?
Here's the source file: http://drop.io/gqdcyp3
Update
I solved it myself, but I don't think it's the optimal solution:
var videos:Array = new Array(
'ltp_video-low1.flv',
'ltp_video-low1.flv',
'ltp_video-low1.flv',
'ltp_video-low1.flv'
);
function videoOver(buttonMC,video,stream) {
buttonMC.onRollOver = function() {
stream.pause(false);
video.attachVideo(stream);
fadeIn(video);
};
}
function videoOut(buttonMC,video,stream) {
buttonMC.onRollOut = function() {
fadeOut(video);
stream.pause();
};
}
for (var i:Number=1; i<=4; i++) {
this['connection'+i] = new NetConnection();
this['connection'+i].connect(null);
this['stream'+i] = new NetStream(this['connection'+i]);
this['stream'+i].play(videos[i-1]);
videoOver(this['videobutton'+i],this['video'+i],this['stream'+i]);
videoOut(this['videobutton'+i],this['video'+i],this['stream'+i]);
}
Anyhow, this works. But it would great if someone could give me a solution created from this, since it works. How can I have the functions in the loop?