2013-11-22 49 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"); 
    } 
} 

我希望这将帮助你:)

相关问题