我试图在用户点击按钮时停止播放歌曲,这是我的代码:
var mySound:MainSound = new MainSound();
var cmyChannel :SoundChannel;
animation_play.addEventListener(MouseEvent.CLICK, playSound);
function playSound(event:Event) {
mySound.play();
}
animation_stop.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(event:Event) {
mySound.stop();
}
animation_play.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);
function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}
当我点击animation_play对象时,它完全正常,它通过播放声音并从指定帧开始动画来实现。但是如果我点击animation_stop对象我会收到错误
TypeError: Error #1006: stop is not a function.
任何人都知道如何解决这个问题?
答案 0 :(得分:2)
要停止声音,您必须使用这样的SoundChannel
对象,例如:
function playSound(event:Event): void
{
cmyChannel = mySound.play();
}
和
function stopSound(event:Event): void
{
cmyChannel.stop();
}
希望可以提供帮助。
答案 1 :(得分:2)
您需要将mySound.play()
设置为cmyChannel
对象。然后在stop
上致电cmyChannel
。这是代码:
var mySound:MainSound = new MainSound();
var cmyChannel :SoundChannel;
animation_play.addEventListener(MouseEvent.CLICK, playSound);
function playSound(event:Event) {
cmyChannel = mySound.play();
}
animation_stop.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(event:Event) {
cmyChannel.stop();
}
animation_play.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);
function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}