实例化嵌入类这样的:
[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工作,谢谢:) – 2011-02-24 09:57:26
感谢您的帖子。有趣的是,我不得不将整个soundTransform属性重新分配给SoundTransform的一个新实例,并且只设置soundTransform上的volume属性不起作用 – 2013-07-12 05:28:10