mx.core

# SoundAsset - AS3 Flex

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

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
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | bytesLoaded : uint [read-only] Returns the currently available number of bytes in this sound object. | Sound
|  | bytesTotal : int [read-only] Returns the total number of bytes in this sound object. | Sound
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | id3 : ID3Info [read-only] Provides access to the metadata that is part of an MP3 file. | Sound
|  | isBuffering : Boolean [read-only] Returns the buffering state of external MP3 files. | Sound
|  | isURLInaccessible : Boolean [read-only] Indicates if the Sound.url property has been truncated. | Sound
|  | length : Number [read-only] The length of the current sound in milliseconds. | Sound
|  | url : String [read-only] The URL from which this sound was loaded. | Sound

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | SoundAsset() 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
|  | close():void Closes the stream, causing any download of data to cease. | Sound
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | extract(target:ByteArray, length:Number, startPosition:Number = -1):Number Extracts raw sound data from a Sound object. | Sound
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | load(stream:URLRequest, context:SoundLoaderContext = null):void Initiates loading of an external MP3 file from the specified URL. | Sound
|  | loadCompressedDataFromByteArray(bytes:ByteArray, bytesLength:uint):void 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
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | complete | Dispatched when data has loaded successfully. | Sound
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | id3 | Dispatched by a Sound object when ID3 data is available for an MP3 sound. | Sound
|  | ioError | Dispatched when an input/output error occurs that causes a load operation to fail. | Sound
|  | open | Dispatched when a load operation starts. | Sound
|  | progress | Dispatched when data is received as a load operation progresses. | Sound
|  | sampleData | Dispatched 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.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00