我再次在这里寻求你的帮助:{我有一个问题,我试着在谷歌上搜索,但找不到答案。嗯,..May是有答案的,但我就是不能让它工作?我正在学习AS3的过程中,所以假设我在这里还是个新手。
我正在做的是做一个键盘来响应我有的vdo文件。这是一个非常简单的想法,即按n-play。每个键都有自己的vdo要播放,如果你在按下第一个键的同时按下另一个按钮,它将播放其键的另一个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将一直播放到结束。如果有多个按钮按住,只需播放最后按下的按钮的vdo。
谢谢。
Ps。我试过removeEventListener,但它使所有按钮的功能都消失了。
发布于 2013-11-22 18:01:35
你的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");
}
}我希望这会对您有所帮助:)
https://stackoverflow.com/questions/20138749
复制相似问题