Actionscript 3 actionscript 3按键释放停止声音
嗨,我真的是一个新的动作脚本,我有一个问题,发挥声音。当我松开向上键时,我希望我的声音停止播放。我设法用按键播放声音 这是我的密码Actionscript 3 actionscript 3按键释放停止声音,actionscript-3,flash,audio,keypress,Actionscript 3,Flash,Audio,Keypress,嗨,我真的是一个新的动作脚本,我有一个问题,发挥声音。当我松开向上键时,我希望我的声音停止播放。我设法用按键播放声音 这是我的密码 import flash.events.KeyboardEvent; var mySound:Sound = new carstart(); stage.addEventListener(KeyboardEvent.KEY_DOWN, playSound); stage.addEventListener(KeyboardEvent.KEY_UP, stopSou
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();
}
}