ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
mx.core 

SoundAsset  - AS3 Flex

Packagemx.core
Classpublic class SoundAsset
InheritanceSoundAsset Inheritance Sound Inheritance EventDispatcher Inheritance Object
Implements IFlexAsset

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

SoundAsset is a subclass of the flash.media.Sound class which represents sounds that you embed in a Flex application.

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}"/>



Public Properties
 PropertyDefined By
 InheritedbytesLoaded : uint
[read-only] Returns the currently available number of bytes in this sound object.
Sound
 InheritedbytesTotal : int
[read-only] Returns the total number of bytes in this sound object.
Sound
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedid3 : ID3Info
[read-only] Provides access to the metadata that is part of an MP3 file.
Sound
 InheritedisBuffering : Boolean
[read-only] Returns the buffering state of external MP3 files.
Sound
 InheritedisURLInaccessible : Boolean
[read-only] Indicates if the Sound.url property has been truncated.
Sound
 Inheritedlength : Number
[read-only] The length of the current sound in milliseconds.
Sound
 Inheritedurl : String
[read-only] The URL from which this sound was loaded.
Sound
Public Methods
 MethodDefined By
  
Constructor.
SoundAsset
 Inherited
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
 Inherited
Closes the stream, causing any download of data to cease.
Sound
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
extract(target:ByteArray, length:Number, startPosition:Number = -1):Number
Extracts raw sound data from a Sound object.
Sound
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
load(stream:URLRequest, context:SoundLoaderContext = null):void
Initiates loading of an external MP3 file from the specified URL.
Sound
 Inherited
load MP3 sound data from a ByteArray object into a Sound object.
Sound
 Inherited
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
 Inherited
play(startTime:Number = 0, loops:int = 0, sndTransform:flash.media:SoundTransform = null):SoundChannel
Generates a new SoundChannel object to play back the sound.
Sound
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 InheritedDispatched when data has loaded successfully.Sound
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
 InheritedDispatched by a Sound object when ID3 data is available for an MP3 sound.Sound
 InheritedDispatched when an input/output error occurs that causes a load operation to fail.Sound
 InheritedDispatched when a load operation starts.Sound
 InheritedDispatched when data is received as a load operation progresses.Sound
 InheritedDispatched when the runtime requests new audio data.Sound
Constructor Detail

SoundAsset

()Constructor
public function SoundAsset()

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Constructor.