Actionscript 2.0 Apply sound on keydown

时间:2015-07-31 19:55:05

标签: flash audio actionscript-2

I am coding a Flash app in AS2 and I need help. I want it so that when my character jumps, a sound effect can be heard. Here is what I've tried.

if (Key.isDown(Key.UP) {
    jump.wav.start();
}

This code is applied on character. There is other code applied on my character, here it is. The instance name of the character is char.

I was exploring on the internet for about 20 minutes and nothing I tried works. The name of sound is jump and it is a .wav file.

I think that I wrote all that I need.

Every answer is very helpful! :)

1 个答案:

答案 0 :(得分:0)

要在Key.UP关闭角色时播放声音,您可以使用attachSound()这样的方法:

if (Key.isDown(Key.UP)) {
    sound = new Sound(this);
    // where "jump_sound" is the AS linkage identifier of your sound
    sound.attachSound('jump_sound');     
    sound.start(0, 1);
}

希望可以提供帮助。