在搜索如何更改音量时,我总是得到这个令人讨厌的snd=new Sound(URLRequest)
,然后是snd.setVolume(val)
。哦,很好,但是我的声音不是URLRequest,而是嵌入的。
我做了很多随机尝试(1)都没有用。我应该怎么做呢?
(1)包括将我的类强制转换为Sound,使用embed类作为参数创建Sound,创建SoundTransform并将其设置为通道等。
最佳答案
实例化您的嵌入式类,如下所示:
[Embed(source="MySound.mp3")]
public var soundClass:Class;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var smallSound:Sound = new soundClass() as Sound;
var trans:SoundTransform = new SoundTransform(.01);
smallSound.play(0,0,trans);
}
更新:
如果您真正想知道的是在声音已经播放的情况下如何更改音量:
[Embed(source="MySound.mp3")]
public var soundClass:Class;
public var smallSound : Sound;
public var vol : Number = 0.01;
public var trans : SoundTransform;
public var chan : SoundChannel = new SoundChannel();
protected function application1_creationCompleteHandler(event:FlexEvent):void {
smallSound = new soundClass() as Sound;
trans = new SoundTransform(vol);
chan = smallSound.play(0,0,trans);
}
protected function volUp_clickHandler(event:MouseEvent):void {
vol += .1;
trans = new SoundTransform(vol);
chan.soundTransform = trans;
}
关于apache-flex - Flex:如何更改EMBEDDED声音的音量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5094192/