当我按下空格键并激发激光时,试图找出我的船的代码
private var reqButton:URLRequest = new URLRequest("laser.mp3");
private var buttonSound:Sound = new Sound(reqButton);
if (key.isDown(Keyboard.SPACE))
{
fireBullet();
buttonSound.play();
}
好的,我只需要添加两件事
import flash.net.URLRequest;
import flash.media.Sound;
答案 0 :(得分:0)
如果您在“音频”文件夹中有外部声音,可以尝试此操作
var reqButton:URLRequest = new URLRequest("audio/button.mp3");
var buttonSound:Sound = new Sound(reqButton);
然后是你的按键代码:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
function keyDown(event:KeyboardEvent):void
{
switch(event.charCode)
{
case 32: //Space Bar
//trace("Space Bar");
buttonSound.play();
break;
}
}