套件 | mx.core |
類別 | public class SoundAsset |
繼承 | SoundAsset Sound EventDispatcher Object |
實作 | IFlexAsset |
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
The sound that you're embedding can be in an MP3 file. You can also embed a sound symbol that is in a SWF file produced by Flash. In both cases, the MXML compiler autogenerates a class that extends SoundAsset to represent the embedded sound data.
You don't generally have to use the SoundAsset class directly when you write a Flex application. For example, you can embed an MP3 file and use it in a SoundEffect simply by writing the following:
<mx:SoundEffect id="beep" source="@Embed(source='Beep.mp3')"/>
without having to understand that the MXML compiler has created a subclass of SoundAsset for you.
However, it may be useful to understand what is happening
at the ActionScript level.
To embed a bitmap in ActionScript, you declare a variable
of type Class, and put [Embed]
metadata on it.
For example, you embed an MP3 file like this:
[Bindable] [Embed(source="Beep.mp3")] private var beepClass:Class;
The MXML compiler sees the .mp3 extension, transcodes the MP3 data
into the sound format that the player uses, autogenerates
a subclass of the SoundAsset class, and sets your variable
to be a reference to this autogenerated class.
You can then use this class reference to create instances of the
SoundAsset using the new
operator, and you can use
APIs of the Sound class on them:
var beepSound:SoundAsset = SoundAsset(new beepClass()); beepSound.play();
However, you rarely need to create SoundAsset instances yourself
because sound-related properties and styles can simply be set to a
sound-producing class, and components will create sound instances
as necessary.
For example, to play this sound with a SoundEffect, you can
set the SoundEffect's source
property to
beepClass
.
In MXML you could do this as follows:
<mx:SoundEffect id="beepEffect" source="{beepClass}"/>
方法 | 定義自 | ||
---|---|---|---|
Constructor. | SoundAsset | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
會在 EventDispatcher 物件註冊事件偵聽程式,以便讓偵聽程式收到事件的通知。 | EventDispatcher | ||
會關閉串流,因而導致資料的下載作業終止。 | Sound | ||
會將事件傳送到事件流程。 | EventDispatcher | ||
從 Sound 物件中擷取原始聲音資料。 | Sound | ||
會檢查 EventDispatcher 物件是否有對特定的事件類型註冊偵聽程式。 | EventDispatcher | ||
指出物件是否有已定義的指定屬性。 | Object | ||
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | ||
起始會從指定 URL 載入外部 MP3 檔的作業。 | Sound | ||
將 MP3 聲音資料從 ByteArray 物件載入 Sound 物件。 | Sound | ||
loadPCMFromByteArray(bytes:ByteArray, samples:uint, format:String = "float", stereo:Boolean = true, sampleRate:Number = 44100.0):void
將 PCM 32 位元浮點聲音資料從 ByteArray 物件載入 Sound 物件。 | Sound | ||
play(startTime:Number = 0, loops:int = 0, sndTransform:flash.media:SoundTransform = null):SoundChannel
會產生新的 SoundChannel 物件,以便播放聲音。 | Sound | ||
指出指定的屬性是否存在,以及是否可列舉。 | Object | ||
會從 EventDispatcher 物件移除偵聽程式。 | EventDispatcher | ||
為迴圈作業設定動態屬性的可用性。 | Object | ||
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | ||
會傳回指定之物件的字串形式。 | Object | ||
會傳回指定之物件的基本值。 | Object | ||
檢查此 EventDispatcher 物件是否已註冊事件偵聽程式,或者此物件的任何祖系已為特定事件類型註冊事件偵聽程式。 | EventDispatcher |
SoundAsset | () | 建構函式 |
public function SoundAsset()
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Constructor.
Tue Jun 12 2018, 03:47 PM Z