2009-03-30 6 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]); 
} 

대신 나는 이런 식으로 뭔가를 할 수 있습니다.

// 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에서 비디오 객체에 호출되고 여기에

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

모든 코드입니다.

비디오 객체가 선언 된 코드가 보이지 않지만 거기에 있다고 가정합니다. 코드의 두 번째 부분에서

당신은이 일을하고 있습니다 :
this['videobutton'+i].onRollOver = function() { 
    this['stream'+this.i].pause(false); 
    this.attachVideo(['stream'+this.i]); 
    fadeIn(['video'+this.i]); 
}; 

는 그래서 attachVideo가없는 비디오 객체의 videobutton 객체에서 호출되고있다.

또한 스트림에 대한 참조가 작동하지 않는다고 생각합니다.이 변수는 비디오 버튼 일 것입니다. 비디오 버튼은 정의 된 값이 없습니다 (이 "this"참조는 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

두 번째 코드에서 비디오 객체를 호출하는 방법을 보여줄 수 있습니까? –

+0

어디에 정의되어 있는지 모르겠지만 작동하도록 만드는 방법을 찾아야합니다. – Herms

+0

감사합니다. 모든 것이 루프에있는 솔루션이 필요합니다. 어떤 아이디어? 여기 fla 파일을 얻을 수 있습니다 : http://drop.io/gqdcyp3 –