Actionscript 3 如何按键盘仅播放一次vdo
我再次来到这里寻求您的帮助:{我有一个问题,我试图用谷歌搜索它,但找不到答案。嗯,…可能有答案,但我就是无法让它工作?我正在学习AS3,所以让我们说我还是新来的 我正在做的是制作一个键盘,以响应我拥有的vdo文件。这是一个非常简单的想法,即按下n键播放。每个键都有自己的vdo要播放,如果你在第一个键仍在按下的情况下按下另一个按钮,它将播放其键的另一个vdo。我已将其设置为布尔值,具有keydown和keyup的功能,如下所示:Actionscript 3 如何按键盘仅播放一次vdo,actionscript-3,video,flash-cs6,Actionscript 3,Video,Flash Cs6,我再次来到这里寻求您的帮助:{我有一个问题,我试图用谷歌搜索它,但找不到答案。嗯,…可能有答案,但我就是无法让它工作?我正在学习AS3,所以让我们说我还是新来的 我正在做的是制作一个键盘,以响应我拥有的vdo文件。这是一个非常简单的想法,即按下n键播放。每个键都有自己的vdo要播放,如果你在第一个键仍在按下的情况下按下另一个按钮,它将播放其键的另一个vdo。我已将其设置为布尔值,具有keydown和keyup的功能,如下所示: import flash.events.Event; import
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;
}
}
}
我曾经尝试过在不使用任何布尔值或那些对错的东西的情况下制作一个键控函数来播放vdo。它奏效了,但我仍然有同样的问题,我找不到一个解决方案,那就是
当您按下键盘按钮时,vdo将保持开始
我只想在按下键的情况下播放vdo。如果vdo结束,则以循环方式再次播放,但如果钥匙已打开,则vdo将一直播放到结束。
如果有多个按钮被按下,只需播放最近按下的按钮的vdo
T-T
谢谢
另外,我尝试过removeEventListener,但它使每个按钮的功能都消失了。您的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");
}
}
我希望这将对你有所帮助:请编辑你的帖子,并在带项目符号的简短陈述中明确你想要达到的最佳效果。
// 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");
}
}