您好,我是ActionScript和ive的新手,在播放声音时遇到问题。放开向上键时,我希望声音停止播放。香港专业教育学院(Ive)可以在按键时播放声音。
这是我的代码...
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.
如果您能想到任何事情,那将是很大的帮助。
谢谢
最佳答案
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();
}
}
关于actionscript-3 - ActionScript 3键释放停止声音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10584889/