嗨,我真的很新动作脚本,我有播放声音的问题。当我释放向上键时,我希望我的声音停止播放。 ive manged让声音在按键上播放。
继承我的代码......
import flash.events.KeyboardEvent;
var mySound:Sound = new carstart();
stage.addEventListener(KeyboardEvent.KEY_DOWN, playSound);
stage.addEventListener(KeyboardEvent.KEY_UP, stopSound);
function playSound(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 38) {
mySound.play();
}
}
function stopSound(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 38) {
mySound.stop();
}
}
我收到此错误
Scene 1, Layer 'Actions', Frame 1, Line 29 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound.
如果你能想到任何事情,那将是一个很大的帮助。
感谢
答案 0 :(得分:1)
import flash.events.KeyboardEvent;
var mySound:Sound = new carstart();
var myChannel:SoundChannel = new SoundChannel();
myChannel = mySound.play();
function playSound(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 38) {
mySound.play();
}
}
function stopSound(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 38) {
myChannel.stop();
}
}
答案 1 :(得分:0)
您需要将Sound
对象包装成SoundChannel
...
按照this示例,您将立即设置!