Apache flex Flex:如何更改嵌入式声音的音量?

Apache flex Flex:如何更改嵌入式声音的音量?,apache-flex,actionscript,audio,Apache Flex,Actionscript,Audio,在寻找如何改变声音的音量时,我总是得到这样一个恼人的snd=new Sound(URLRequest),然后是snd.setVolume(val)。哦,很好,但我的声音不是请求,而是嵌入 我做了很多随机的尝试,但都没有成功。我该怎么做呢 (1) 包括将我的类强制转换为声音、使用embed类作为参数创建声音、创建SoundTransform并将其设置为频道等。按如下方式实例化嵌入式类: [Embed(source="MySound.mp3")] public var soundClass:Clas

在寻找如何改变声音的音量时,我总是得到这样一个恼人的
snd=new Sound(URLRequest)
,然后是
snd.setVolume(val)
。哦,很好,但我的声音不是请求,而是嵌入

我做了很多随机的尝试,但都没有成功。我该怎么做呢


(1) 包括将我的类强制转换为声音、使用embed类作为参数创建声音、创建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;
}

按如下方式实例化嵌入式类:

[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;
}

是的,我想改变已经播放的声音的音量。声音转换成功了,谢谢:)谢谢你的帖子。有趣的是,我不得不将整个soundTransform属性重新分配给soundTransform的一个新实例,并且仅在soundTransform上设置音量属性不起作用。是的,我想更改已经播放的声音的音量。声音转换成功了,谢谢:)谢谢你的帖子。有趣的是,我不得不将整个soundTransform属性重新分配给soundTransform的一个新实例,而仅在soundTransform上设置音量属性是不起作用的