2013-11-22 80 views
1

我在這裏再次尋求幫助:{我有一個問題,我試圖谷歌它,但無法找到答案。那麼,..可能有一個答案,但我不能讓它的作品?我正在學習AS3,所以假設我在這裏仍然是新手。我怎樣才能按鍵盤只玩一次vdo

我在做什麼是製作keyboatd與VDO文件,我有迴應。這是一個非常簡單的想法,即按即玩。每個按鍵都有自己vdos玩,如果你按下另一個按鈕,而第一個仍然堅持,它會發揮其關鍵的另一VDO。我做這與的keydown的功能布爾和KEYUP這樣的:

import flash.events.Event; 
import flash.events.KeyboardEvent; 
import flash.net.NetStream; 
import flash.net.NetConnection; 
import flash.media.Video; 

var isLeft:Boolean = false; 
var isRight:Boolean = false; 
    var video; 
var nc; 
var ns; 
stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown); 
stage.addEventListener(KeyboardEvent.KEY_UP,onUP); 
this.addEventListener(Event.ENTER_FRAME,playVid); 

       nc = new NetConnection(); 
       nc.connect(null); 
       ns = new NetStream(nc); 
       ns.client = this; 
       video = new Video(550,400); 
       addChild(video); 
       video.attachNetStream(ns); 


function onDown(e:KeyboardEvent):void 
{ 
     switch (e.keyCode) 
     { 
       case 37 : 
          //ns.play(TomAndJerry.flv); 
          isLeft=true; 
          break; 
       case 39 : 
          //ns.play(westler.flv); 
          isRight = true; 
          break; 
     } 

}

function onUP(e:KeyboardEvent):void 
{ 
     switch (e.keyCode) 
     { 
       case 37 : 
          isLeft = false; 
          break; 
       case 39 : 
          isRight = false; 
          break; 
     } 
} 

function playVid(e:Event):void 
{ 
     if (isLeft) 
     { 
       trace(kk); 
       ns.play(westler.flv); 
       isLeft = false; 
     } 
     else if (isRight) 
     { 
       trace(PP); 
       ns.play(TomAndJerry.flv); 
       //isRight = false; 
     } 

}

我已經嘗試製作的keydown功能,而無需使用任何布爾或那些真正的虛假的事情只是玩虛擬主機。它的工作,但我仍然有我不能找到一個解決方案,它是同一個問題....

當你按住鍵盤按鍵的VDO將繼續從頭開始。

所有我想要的是發揮VDO甚至關鍵是按下去。如果VDO結束然後再發揮循環,但如果該鍵是向上VDO將起到直到它結束。 如果有一個以上的按鈕被按下剛玩最新的按下的按鈕的VDO。

TT」 感謝。

詩。我已經試過removeEventListener但是,它使每一個按鈕的功能了。

+0

請編輯你的帖子,並明確你想要在項目簡短的陳述中達到最佳效果。 –

回答

0

您playvid函數被調用每一個幀,所以我認爲這是正常的錄像不開始,
我認爲你可以試着改變你的代碼如下:

// add net status handler event to check the end of the video 
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
// remove this line  
//this.addEventListener(Event.ENTER_FRAME,playVid); 

/** a key is pressed **/ 
function onDown(e:KeyboardEvent):void 
{ 
    switch (e.keyCode) 
    { 
      case Keyboard.LEFT: 
         // start the video just if the video don't play 
         if(!isLeft) ns.play("TomAndJerry.flv"); 
         // video left is playing 
         isLeft = true; 
         // video right isn't playing 
         isRight = false; 
         break; 

      case Keyboard.RIGHT: 
         // start the video just if the video don't play 
         if(!isRight) ns.play("westler.flv"); 
         // video rightis playing 
         isRight = true; 
         // video left isn't playing 
         isLeft = false; 
         break; 
    } 
} 

/** a key is released **/ 
function onUP(e:KeyboardEvent):void 
{ 
    switch (e.keyCode) 
    { 
      case Keyboard.LEFT: 
         isLeft = false; 
         break; 
      case Keyboard.RIGHT: 
         isRight = false; 
         break; 
    } 
} 

/** net status change, verify if we reach the end of the video **/ 
function netStatusHandler(e:NetStatusEvent):void 
{ 
    // when netStatus code is NetStream.Play.Stop the video is complete 
    if (e.info.code == "NetStream.Play.Stop") 
    { 
     // right key is still pressed we loop the video 
     if(isRight)  ns.play("westler.flv"); 
     // left key is still pressed we loop the video 
     else if(isLeft) ns.play("TomAndJerry.flv"); 
    } 
} 

我希望這將幫助你:)

相關問題