我已经试过这个小时。必须有一个简单的解决方案来停止声音并将其卸载为as3。as3声音类卸载声音
这不是我所有的代码,但总之我加载了随机声音。我需要certian vars以外的功能,所以我可以引用他们与进度条的其他功能。
如何卸载声音,以便我可以使用相同的名称加载新的声音而不会在第二次调用它时发生错误?
我在这个测试中有两个按钮。播放声音和停止声音按钮。
这里是我的代码:
var TheSound:Sound = new Sound();
var mySoundChannel:SoundChannel = new SoundChannel();
PlayButton.addEventListener(MouseEvent.CLICK, PlaySound);
StopButton.addEventListener(MouseEvent.CLICK, Stopsound);
function PlaySound(e:MouseEvent)
{
TheSound.load(new URLRequest("http://www.MyWebsite.com/Noel.mp3"));
mySoundChannel = TheSound.play(0);
}
function StopSound(e:MouseEvent)
{
delete TheSound;
}
以下是错误我得到:
Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at Untitled_fla::MainTimeline/PlaySound()[Untitled_fla.MainTimeline::frame1:21]
UPDATE ....我试过回采的声音,然后卖掉,如下
mySoundChannel.stop();
TheSound.close();
但现在我得到这个错误:
Error: Error #2029: This URLStream object does not have a stream opened.
at flash.media::Sound/close()
at Untitled_fla::MainTimeline/shut1()[Untitled_fla.MainTimeline::frame1:35]
我相信我更接近。非常感谢您的帮助。
哎感谢您的快速帮助。好吧,我试过你的代码,但我得到一个新的错误。我把它贴在上面。 – 2011-12-27 03:59:20
我相信它应该没问题,如果你只是删除关闭流的部分。 – joelrobichaud 2011-12-27 04:15:23
好吧,它停止流,但是当我点击重新加载它时,它得到上面提到的第一个错误 “以不正确的顺序调用函数,或者更早的调用不成功。” – 2011-12-27 04:17:25