實例化嵌入類這樣的:
[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