onRollOver を使用したこの For ループを機能させることができません。
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]);
};
}
変数のスコープとiに関係していると思いますが、修正方法がわかりません。
トレースは私に与えます:5
何か案は?
ソース ファイルは次のとおりです: http://drop.io/gqdcyp3
更新
自分で解決しましたが、最適な解決策ではないと思います:
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]);
}
とにかく、これは機能します。しかし、それが機能するので、誰かがこれから作成されたソリューションを私に提供できれば素晴らしいと思います. 関数をループに入れるにはどうすればよいですか?