flash as3制作的键盘钢琴有延迟

我用AS3写了个键盘钢琴,不知道为什么弹的时候声音总是慢一拍,请问有谁可以帮我解决这个问题stage.addEventListener(KeyboardEvent.KEY... 我用AS3写了个键盘钢琴,不知道为什么弹的时候声音总是慢一拍,请问有谁可以帮我解决这个问题
stage.addEventListener(KeyboardEvent.KEY_DOWN,an);
function an(ancs:KeyboardEvent):void {
//trace(ancs.keyCode);
if (ancs.keyCode==65) {
var drum:sound1 = new sound1();
var channel:SoundChannel = drum.play();
} else if (ancs.keyCode==66) {
var s1:sound2 = new sound2();
var channel1:SoundChannel = s1.play();
} else if (ancs.keyCode==72) {
var s7:sound8 = new sound8();
var channel7:SoundChannel = s7.play();
} else if (ancs.keyCode==73) {
var s8:sound9 = new sound9();
var channel8:SoundChannel = s8.play();
} else if (ancs.keyCode==74) {
var s9:sound10 = new sound10();
var channel9:SoundChannel = s9.play();
} else if (ancs.keyCode==75) {
var s10:sound11 = new sound11();
var channel10:SoundChannel = s10.play();
} else if (ancs.keyCode==76) {
var s11:sound12 = new sound12();
var channel11:SoundChannel = s11.play();
} else if (ancs.keyCode==77) {
var s12:sound13 = new sound13();
var channel12:SoundChannel = s12.play();
} else if (ancs.keyCode==78) {
var s13:sound14 = new sound14();
var channel13:SoundChannel = s13.play();
} else if (ancs.keyCode==79) {
var s14:sound15 = new sound15();
var channel14:SoundChannel = s14.play();
} else if (ancs.keyCode==80) {
var s15:sound16 = new sound16();
var channel15:SoundChannel = s15.play();
} else if (ancs.keyCode==81) {
var s16:sound17 = new sound17();
var channel16:SoundChannel = s16.play();
} else if (ancs.keyCode==82) {
var s17:sound18 = new sound18();
var channel17:SoundChannel = s17.play();
} else if (ancs.keyCode==83) {
var s18:sound19 = new sound19();
var channel18:SoundChannel = s18.play();
} else if (ancs.keyCode==84) {
var s19:sound20 = new sound20();
var channel19:SoundChannel = s19.play();
} else if (ancs.keyCode==85) {
var s20:sound21 = new sound21();
var channel20:SoundChannel = s20.play();
} else if (ancs.keyCode==86) {
var s21:sound22 = new sound22();
var channel21:SoundChannel = s21.play();
} else if (ancs.keyCode==87) {
var s22:sound23 = new sound23();
var channel22:SoundChannel = s22.play();
} else if (ancs.keyCode==88) {
var s23:sound24 = new sound24();
var channel23:SoundChannel = s23.play();
} else if (ancs.keyCode==89) {
var s24:sound25 = new sound25();
var channel24:SoundChannel = s24.play();
} else if (ancs.keyCode==90) {
var s25:sound26 = new sound26();
var channel25:SoundChannel = s25.play();
}
}
这是我写在里面的代码
展开
 我来答
缺钙童子
推荐于2016-01-19 · TA获得超过279个赞
知道小有建树答主
回答量:488
采纳率:0%
帮助的人:367万
展开全部
你先不要用IF {} 用SWITH CASE试试
var sound:Sound;
var soundchannel:SoundChannel=new SoundChannel();
stage.addEventListener(KeyboardEvent.KEY_DOWN,an);
function an(ancs:KeyboardEvent):void {
swith case ancs.keyCode{
case 65:
sound=new Sound1();
soundchannel=sound.play();
break;
case 66:
sound=new Sound2();
soundchannel=sound.play();
break;
.....
}
}
PS.你写得没有效率
我的没有检验 也不一定对
sound1....sound26是你写得Sound的子类?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式