首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >进入下一帧时停止声音- Adobe动画/AS3

进入下一帧时停止声音- Adobe动画/AS3
EN

Stack Overflow用户
提问于 2019-11-15 00:55:31
回答 1查看 3K关注 0票数 1

我有三个画面,每一个都有自己的动画电影剪辑。要进入下一个场景,您可以在当前场景上按一个按钮,然后将其转到第二帧。

我在三个电影剪辑中每个都有音频,但是当我点击按钮进入第二场景时,来自第一场景的音频继续播放。

当我单击到第二帧时,来自第1帧电影剪辑的音频停止,而第2帧电影剪辑音频开始?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-15 07:18:46

确保将SoundChannel附加到声音对象。

然后简单地在next按钮函数中分配一个soundChannel.stop()

框架1:

代码语言:javascript
复制
//create a sound class to hold the sound
var f1sound:Sound = new Sound();
//soundchannel to control your sound to play and pause
var sChannel:SoundChannel = new SoundChannel();

//this setup function will load and autoplay your sound file
function setUp():void {
    f1sound.load(new URLRequest("frame1sound.mp3")); //load your sound file
    f1sound.play();

    //add the event for the Next Button, remember to change it to your actual button name
    nextButton.addEventListener(MouseEvent.MOUSE_DOWN, nextBtnDown);
}

function nextBtnDown():void {
    nextButton.removeEventListener(MouseEvent.MOUSE_DOWN, nextBtnDown);
    sChannel.stop(); //this stop the audio
    f1sound.close(); //this unloads the sound stream for cleaning purposes

    gotoAndStop(2); //go to frame 2, put this as the last line of the function
}

setUp();  //this will make the program run setUp function on the first run, once.

下一个框架基本上与这个框架是相同的,只要您保持这种格式,不管您跳到哪个帧,来回跳,它都应该工作。还有其他的优化要做,如只播放音频后,它已完全加载,但我会留下他们为您查找和探索。祝好运。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58868791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档