使用 ActionScript 3 声音淡入/淡出

发布于 2024-09-26 15:59:20 字数 399 浏览 7 评论 0原文

我正在尝试在 Flash (CS5) 项目中淡入/淡出音乐。我将声音导入到库中,为“Export for ActionScript”设置一个类名,然后尝试使用 TweenLite/TweenMax 进行淡入淡出,如下所示:

var sound = new MySound();
sT = new SoundTransform(0.1);
sound.play(0,99999, c_sndEnvironment);
TweenLite.to(sound, 1, {volume: 1.0});

但它不起作用。我尝试在 TweenLite 上导入音量插件,但仍然没有任何结果。但我完全没有错误。

我做错了什么吗?

另外,有没有好的(完整的)AS3 音乐库?

谢谢。 :)

I am trying to make a fade in/out in a music in a Flash (CS5) project. I imported the sound to library, set a classname for "Export for ActionScript", and I was trying to fade with TweenLite/TweenMax, like this:

var sound = new MySound();
sT = new SoundTransform(0.1);
sound.play(0,99999, c_sndEnvironment);
TweenLite.to(sound, 1, {volume: 1.0});

But it just doesn't work. I tried to import the volume plugin on TweenLite, and still nothing. I got no error at all though.

Am I doing anything wrong?

Plus, is there any good (complete) AS3 library for music?

Thank you. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落日海湾 2024-10-03 15:59:20

我为此使用 TweenMax,它非常简单

var someSound:Sound = new Sound(new URLRequest(“MySound.mp3″));
var someChannel:SoundChannel = someSound.play(0, 99999);
TweenMax.to(someChannel, 1, {volume:0, onComplete:stopSound});

http://www.greensock.com/tweenmax/

I use TweenMax for this , it's pretty straightforward

var someSound:Sound = new Sound(new URLRequest(“MySound.mp3″));
var someChannel:SoundChannel = someSound.play(0, 99999);
TweenMax.to(someChannel, 1, {volume:0, onComplete:stopSound});

http://www.greensock.com/tweenmax/

过期以后 2024-10-03 15:59:20

PatrickS 的说法是正确的,您应该调整 SoundChannel 的音量,而不是声音本身。 TweenMax 自动激活 VolumePlugin(以及其他几个),但您可以为 TweenLite 手动执行此操作,例如:

import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([VolumePlugin]); //only necessary once

var someChannel:SoundChannel = someSound.play(0, 99999);
TweenLite.from(someChannel, 1, {volume:0});

对于它的价值,您可能还想查看 LoaderMax,它具有 MP3Loader 类,可以更轻松地处理外部声音。它有自己的“体积”属性,您也可以对其进行补间。 http://www.greensock.com/loadermax/

PatrickS is correct about the fact that you should tween the volume of the SoundChannel, not the Sound itself. TweenMax automatically activates the VolumePlugin (along with several others), but you can do that manually for TweenLite like:

import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([VolumePlugin]); //only necessary once

var someChannel:SoundChannel = someSound.play(0, 99999);
TweenLite.from(someChannel, 1, {volume:0});

For what it's worth, you might also want to check out LoaderMax which has an MP3Loader class that makes working with external sounds easier. It has its own "volume" property that you can tween too. http://www.greensock.com/loadermax/

若水微香 2024-10-03 15:59:20

抱歉,我从这些代码行中发现了一种奇怪的行为。我的声音渐渐消失,悠悠球又回来了。声道与之前音量相同后,onComplete正常执行。有什么想法吗?

themeChannel = sndTheme.play(0, 99999);
TweenLite.from(themeChannel, 2, {volume:0,onComplete:stopTheme});

//编辑:我通过补间 SoundTransform 对象使其工作:

var themeTransform:SoundTransform = new SoundTransform(1);
themeChannel  = sndTheme.play(0, 99999, themeTransform);
TweenLite.from(themeTransform, 3, {volume:0,onUpdate:updateSound,onComplete:stopTheme});

function updateSound():void{
           themeChannel.soundTransform = themeTransform;
        }

感谢:
http://www.zedia.net/2008/fading-out-音量使用-twenlite/

sorry, I kind kind of a strange behaviour from these lines of code. My sound fades out, and yoyos back. after the soundchannel is at the same volume as before, onComplete is executed normally. Any ideas?

themeChannel = sndTheme.play(0, 99999);
TweenLite.from(themeChannel, 2, {volume:0,onComplete:stopTheme});

//edit: I got it working by Tweening a SoundTransform Object:

var themeTransform:SoundTransform = new SoundTransform(1);
themeChannel  = sndTheme.play(0, 99999, themeTransform);
TweenLite.from(themeTransform, 3, {volume:0,onUpdate:updateSound,onComplete:stopTheme});

function updateSound():void{
           themeChannel.soundTransform = themeTransform;
        }

thanks to:
http://www.zedia.net/2008/fading-out-volume-using-tweenlite/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文