Package | mx.core |
Class | public class SoundAsset |
Inheritance | SoundAsset Sound EventDispatcher Object |
Implements | IFlexAsset |
Language Version: | ActionScript 3.0 |
Product Version: | Flex 3 |
Runtime Versions: | 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}"/>
Method | Defined By | ||
---|---|---|---|
Constructor. | SoundAsset | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Closes the stream, causing any download of data to cease. | Sound | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Extracts raw sound data from a Sound object. | Sound | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Initiates loading of an external MP3 file from the specified URL. | Sound | ||
load MP3 sound data from a ByteArray object into a Sound object. | Sound | ||
loadPCMFromByteArray(bytes:ByteArray, samples:uint, format:String = "float", stereo:Boolean = true, sampleRate:Number = 44100.0):void
load PCM 32-bit floating point sound data from a ByteArray object into a Sound object. | Sound | ||
play(startTime:Number = 0, loops:int = 0, sndTransform:flash.media:SoundTransform = null):SoundChannel
Generates a new SoundChannel object to play back the sound. | Sound | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
SoundAsset | () | Constructor |
public function SoundAsset()
Language Version: | ActionScript 3.0 |
Product Version: | Flex 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Constructor.
Mon Nov 28 2011, 06:48 AM -08:00