搜索如何更改声音的音量,我总是会感到恼火snd=new Sound(URLRequest)
,然后是snd.setVolume(val)
。哦,很好,但我的声音不是URLRequest,它是一个嵌入。
我做了很多随机尝试(1)无济于事。我该怎么做呢?
(1)包括将我的类转换为Sound,使用embed类作为参数创建一个Sound,创建一个SoundTransform并将其设置为通道等。
答案 0 :(得分:3)
像这样实例化您的嵌入式类:
[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;
}