2011-02-23 66 views
0

尋找如何改變聲音的音量,我總是得到這個惱人的snd=new Sound(URLRequest),其次是snd.setVolume(val)。哦,很好,但我的聲音不是URLRequest,它是一個嵌入。Flex:如何改變EMBEDDED聲音的音量?

我做了很多隨機嘗試(1)無濟於事。我應該怎麼做呢?

(1),其包括鑄造我的類聲音,創建與所述嵌入類作爲參數,創建的SoundTransform並將其設置到信道一個聲音等

回答

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; 
} 
+0

是的,我想改變已播放聲音的音量。 SoundTransform工作,謝謝:) – 2011-02-24 09:57:26

+0

感謝您的帖子。有趣的是,我不得不將整個soundTransform屬性重新分配給SoundTransform的一個新實例,並且只設置soundTransform上的volume屬性不起作用 – 2013-07-12 05:28:10