Apache Flex 4.16.1 API Reference | All Packages | All Classes | Index | Frames No Frames |
SoundAsset

Package | mx.core
Class | public class SoundAsset
Inheritance | SoundAsset flash.media.Sound
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 Methods

| Method | Defined By
--- | --- | ---
|  | SoundAsset() Constructor. | SoundAsset

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.

Wed Nov 15 2017, 09:50 AM +01:00