2009-03-30 10 views
0

私は4つのflvムービーをプリロードしていて、それらを非表示にしています。ビデオクリップのムービークリップをロールオーバーすると、flvビデオがフェードインして再生を開始します。私はこの作業コードを持っていますが、それは非常にひどく書かれていると感じています。 しかし、これは動作しません、私は思うのattachVideo()と間違って何か:Netstream()ループの問題

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]); 
} 

は、代わりに私はこのような何かをしたいです。ここで

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('ltp_video-low1.flv'); 
    this['videobutton'+i].i = i; 
    this['videobutton'+i].onRollOver = function() { 
     this['stream'+this.i].pause(false); 
     this.attachVideo(['stream'+this.i]); 
     fadeIn(['video'+this.i]); 
    }; 
    this['videobutton'+i].onRollOut = function() { 
     this['stream'+this.i].pause(); 
     this.attachVideo(['stream'+this.i]); 
     fadeOut(['video'+this.i]); 
    }; 
} 

は、すべてのコードです:あなたが持っているあなたの元のコードで

// Import TweenLite 
import gs.*; 
import gs.easing.*; 

// Creates the fade functions 
function fadeIn(video) { 
    TweenLite.to(video,0.5,{_alpha:100, ease:Regular.easeOut}); 
} 
function fadeOut(video) { 
    TweenLite.to(video,0.5,{_alpha:0, ease:Regular.easeOut}); 
} 

// Parses the Flashvars into arrays 
var titles:Array = (_level0.titleVars) ? _level0.titleVars.split(',') : []; 
var urls:Array = (_level0.urlVars) ? _level0.urlVars.split(',') : []; 

// Sets the mouse action 
function SetMouseAction(indexNumber, buttonMC, arrowMC, dynamicTF, linkURL):Void { 
    buttonMC.colorText = dynamicTF; 
    buttonMC.onRollOver = function() { 
     TweenLite.to(arrowMC,0.2,{_x:"2", _alpha:80, ease:Back.easeOut, tint:0x7cb0b7}); 
     this.colorText.textColor = 0x7cb0b7; 
     // Fixes the Flash bug with button over each other 
     if (indexNumber == 1 || indexNumber == 2 || indexNumber == 3) { 
      stream1.pause(false); 
      fadeIn(video1); 
     } 
     if (indexNumber == 4 || indexNumber == 5 || indexNumber == 6) { 
      stream2.pause(false); 
      fadeIn(video2); 
     } 
     if (indexNumber == 7 || indexNumber == 8 || indexNumber == 9) { 
      stream3.pause(false); 
      fadeIn(video3); 
     } 
     if (indexNumber == 10 || indexNumber == 11 || indexNumber == 12) { 
      stream4.pause(false); 
      fadeIn(video4); 
     } 
    }; 
    buttonMC.onRollOut = function() { 
     TweenLite.to(arrowMC,0.2,{_x:37, _alpha:100, ease:Back.easeOut, tint:0xFFFFFF}); 
     this.colorText.textColor = 0xffffff; 
    }; 
    buttonMC.onRelease = function() { 
     if (linkURL) { 
      getURL(linkURL); 
     } 
    }; 
} 

// Loops trough all the MC 
for (var i:Number = 1; i<=12; i++) { 
    SetMouseAction(i,this["link"+i],this["arrow"+i],this["text"+i],urls[i-1]); 
    this["text"+i].text = titles[i-1]; 
} 





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]); 
} 



/* 
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('ltp_video-low1.flv'); 
    this['videobutton'+i].i = i; 
    this['videobutton'+i].onRollOver = function() { 
     this['stream'+this.i].pause(false); 
     this.attachVideo(['stream'+this.i]); 
     fadeIn(['video'+this.i]); 
    }; 
    this['videobutton'+i].onRollOut = function() { 
     this['stream'+this.i].pause(); 
     this.attachVideo(['stream'+this.i]); 
     fadeOut(['video'+this.i]); 
    }; 
} 
*/ 

答えて

1

:この場合

function videoOver(buttonMC,video,stream) { 
    buttonMC.onRollOver = function() { 
    stream.pause(false); 
    video.attachVideo(stream); 
    fadeIn(video); 
    }; 
} 

videoOver(this['videobutton'+i],this['video'+i],this['stream'+i]); 

のattachVideoビデオオブジェクトで呼び出されています。

ビデオオブジェクトが宣言されているコードでは表示されませんが、その場所にあると仮定します。

this['videobutton'+i].onRollOver = function() { 
    this['stream'+this.i].pause(false); 
    this.attachVideo(['stream'+this.i]); 
    fadeIn(['video'+this.i]); 
}; 

だから、あるattachVideoがvideobuttonオブジェクトではなく、ビデオオブジェクトで呼び出されている:あなたはこれをやっているコードの2番目の部分で

また、ストリームへの参照は機能しません。あなたのこの変数は、私が知る限り、その値が定義されていないビデオテーブルです。 function(){}はその外部の参照と同じではありません)。

私はスコープが台無しになると思うので、私はfadeInの呼び出しが間違って動作するかもしれないと思います。


ここには機能するものがあります。私はまったくそれをテストしていないが、うまくいけば、私がしようとしていることのアイデアを得るだろう。

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('ltp_video-low1.flv'); 
    this['videobutton'+i].i = i; 
    setHandlers(i); 
} 

function onVideoButtonRollOver(i:Number):Void { 
    this['stream' + i].pause(false); 
    this.attachVideo(this['stream' + i]); 
    this.fadeIn(this['video' + i]); 
} 

function onVideoButtonRollOut(i:Number):Void { 
    this['stream' + i].pause(); 
    fadeOut(this['video' + i]); 
} 

function setHandlers(i:Number):Function { 
    this['videobutton'+i].scope = this; 
    // This essentially fixes the scope issue. The value of i is retained 
    // properly due to the property of closures. 
    this['videobutton'+i].onRollOver = function() { 
    this.scope.onVideoButtonRollOver.apply(this.scope, [i]); 
    } 
    this['videobutton'+i].onRollOut = function() { 
    this.scope.onVideoButtonRollOut.apply(this.scope, [i]); 
    } 
} 

私はこれに本当に満足していませんが、私はコードをおそらくリファクタリングする必要がありますので、あなたは常にストリームを参照する必要はありませんように物事をきれいにすると思う "ストリーム"、 "接続"などのメンバーと、グループごとに単一のオブジェクトを持っているインデックスに追加します。

+0

2番目のコードでビデオオブジェクトをどのように呼び出すことができますか? –

+0

どこに定義されているのか分かりませんが、動作させる方法を考え出します。 – Herms

+0

ありがとうございます。私はすべてがループの中にあるソリューションが必要ですが。何か案は?ここでflaファイルを入手できます:http://drop.io/gqdcyp3 –