mx.effects

# SoundEffect - AS3 Flex

Package | mx.effects
Class | public class SoundEffect
Inheritance | SoundEffect Effect EventDispatcher Object

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The SoundEffect class plays an MP3 audio file. For example, you could play a sound when a user clicks a Button control. This effect lets you repeat the sound, select the source file, and control the volume and pan.

You specify the MP3 file using the `source` property. If you have already embedded the MP3 file, using the `Embed` keyword, you can pass the Class object of the MP3 file to the `source` property. Otherwise, specify the full URL to the MP3 file.

MXML Syntax Show MXML Syntax
Hide MXML Syntax

The `<mx:SoundEffect>` tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

      <mx:SoundEffect
        Properties
        id="ID"
        autoLoad="true|false"
        bufferTime="1000"
        loops="0"
        panEasingFunction=""
        panFrom="0"
        source=""
        startTime="0"
        useDuration="true|false"
        volumeEasingFunction="true|false"
        volumeTo="1"

        Events
        complete="No default"
        id3="No default"
        ioError="No default"
        progress="No default"
      />

View the examples

More examples

Using the MX sound effect

Learn more

About effects
Using MX effects
Handling MX effect events
About transitions

Related API Elements

mx.effects.effectClasses.SoundEffectInstance
flash.media.Sound

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | autoLoad : Boolean If true, load the MP3 file when the source has been specified. | SoundEffect
|  | bufferTime : Number = 1000 The SoundEffect class uses an internal Sound object to control the MP3 file. | SoundEffect
|  | className : String [read-only] The name of the effect class, such as "Fade". | Effect
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | customFilter : mx.effects:EffectTargetFilter Specifies a custom filter object, of type EffectTargetFilter, used by the effect to determine the targets on which to play the effect. | Effect
|  | duration : Number Duration of the effect in milliseconds. | Effect
|  | effectTargetHost : mx.effects:IEffectTargetHost A property that lets you access the target list-based control of a data effect. | Effect
|  | filter : String Specifies an algorithm for filtering targets for an effect. | Effect
|  | hideFocusRing : Boolean Determines whether the effect should hide the focus ring when starting the effect. | Effect
|  | instanceClass : Class An object of type Class that specifies the effect instance class class for this effect class. | Effect
|  | isLoading : Boolean [read-only] This property is true if the MP3 has been loaded. | SoundEffect
|  | isPlaying : Boolean [read-only] A read-only flag which is true if any instances of the effect are currently playing, and false if none are. | Effect
|  | loops : int = 0 The number of times to play the sound in a loop, where a value of 0 means play the effect once, a value of 1 means play the effect twice, and so on. | SoundEffect
|  | panEasingFunction : Function The easing function for the pan effect. | SoundEffect
|  | panFrom : Number Initial pan of the Sound object. | SoundEffect
|  | panTo : Number Final pan of the Sound object. | SoundEffect
|  | perElementOffset : Number Additional delay, in milliseconds, for effect targets after the first target of the effect. | Effect
|  | playheadTime : Number Current time position of the effect. | Effect
|  | relevantProperties : Array An Array of property names to use when performing filtering. | Effect
|  | relevantStyles : Array An Array of style names to use when performing filtering. | Effect
|  | repeatCount : int = 1 Number of times to repeat the effect. | Effect
|  | repeatDelay : int = 0 Amount of time, in milliseconds, to wait before repeating the effect. | Effect
|  | sound : Sound [read-only] The Sound object that the MP3 file has been loaded into. | SoundEffect
|  | source : Object The URL or class of the MP3 file to play. | SoundEffect
|  | startDelay : int = 0 Amount of time, in milliseconds, to wait before starting the effect. | Effect
|  | startTime : Number = 0 The initial position in the MP3 file, in milliseconds, at which playback should start. | SoundEffect
|  | suspendBackgroundProcessing : Boolean = false If true, blocks all background processing while the effect is playing. | Effect
|  | target : Object The object to which this effect is applied. | Effect
|  | targets : Array An Array of objects that are targets for the effect. | Effect
|  | triggerEvent : Event The Event object passed to this Effect by the EffectManager when an effect is triggered, or null if the effect is not being played by the EffectManager. | Effect
|  | useDuration : Boolean = true If true, stop the effect after the time specified by the duration property has elapsed. | SoundEffect
|  | volumeEasingFunction : Function The easing function for the volume effect. | SoundEffect
|  | volumeFrom : Number Initial volume of the Sound object. | SoundEffect
|  | volumeTo : Number Final volume of the Sound object. | SoundEffect

Protected Properties
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined By
--- | --- | ---
|  | applyTransitionEndProperties : Boolean This flag controls whether the effect, when run in a transition, automatically applies the property values according to the end state, as opposed to leaving values as set by the effect itself. | Effect
|  | endValuesCaptured : Boolean = false A flag containing true if the end values of an effect have already been determined, or false if they should be acquired from the current properties of the effect targets when the effect runs. | Effect

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | SoundEffect(target:Object = null) Constructor. | SoundEffect
|  | 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
|  | captureEndValues():void Captures the current values of the relevant properties on the effect's targets and saves them as end values. | Effect
|  | captureMoreStartValues(targets:Array):void Captures the current values of the relevant properties of an additional set of targets Flex uses this function when a data change effect is run. | Effect
|  | captureStartValues():void Captures the current values of the relevant properties on the effect's targets. | Effect
|  | createInstance(target:Object = null):IEffectInstance Creates a single effect instance and initializes it. | Effect
|  | createInstances(targets:Array = null):Array Takes an Array of target objects and invokes the createInstance() method on each target. | Effect
|  | deleteInstance(instance:IEffectInstance):void Removes event listeners from an instance and removes it from the list of instances. | Effect
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | end(effectInstance:IEffectInstance = null):void Interrupts an effect that is currently playing, and jumps immediately to the end of the effect. | Effect
|  | getAffectedProperties():Array Returns an Array of Strings, where each String is the name of a property changed by this effect. | Effect
|  | 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():void Loads the MP3 if the source property points to a URL. | SoundEffect
|  | pause():void Pauses the effect until you call the resume() method. | Effect
|  | play(targets:Array = null, playReversedFromEnd:Boolean = false):Array Begins playing the effect. | Effect
|  | 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
|  | resume():void Resumes the effect after it has been paused by a call to the pause() method. | Effect
|  | reverse():void Plays the effect in reverse, if the effect is currently playing, starting from the current position of the effect. | Effect
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | stop():void Stops the effect, leaving the effect targets in their current state. | Effect
|  | 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

Protected Methods
Hide Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | applyValueToTarget(target:Object, property:String, value:*, props:Object):void Used internally by the Effect infrastructure. | Effect
|  | effectEndHandler(event:EffectEvent):void Called when an effect instance has finished playing. | Effect
|  | effectStartHandler(event:EffectEvent):void This method is called when the effect instance starts playing. | Effect
|  | effectStopHandler(event:EffectEvent):void Called when an effect instance has stopped by a call to the stop() method. | Effect
|  | filterInstance(propChanges:Array, target:Object):Boolean Determines the logic for filtering out an effect instance. | Effect
|  | getValueFromTarget(target:Object, property:String):* Called by the captureStartValues() method to get the value of a property from the target. | Effect
|  | initInstance(instance:IEffectInstance):void Copies properties of the effect to the effect instance. | Effect

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 the sound file finishes loading. | SoundEffect
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | effectEnd | Dispatched when one of the effect's instances finishes playing, either when the instance finishes playing or when the effect is interrupted by a call to the end() method. | Effect
|  | effectStart | Dispatched when the effect starts playing. | Effect
|  | effectStop | Dispatched when the effect has been stopped, which only occurs when the effect is interrupted by a call to the stop() method. | Effect
|  | id3 | Dispatched when ID3 data is available for an MP3 sound file. | SoundEffect
|  | ioError | Dispatched when an error occurs during the loading of the sound file. | SoundEffect
|  | progress | Dispatched periodically as the sound file loads. | SoundEffect

Property Detail

### autoLoad

property

`autoLoad:Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

If `true`, load the MP3 file when the `source` has been specified.

The default value is `true.`

Implementation
`public function get autoLoad():Boolean`
`public function set autoLoad(value:Boolean):void`

### bufferTime

property

`public var bufferTime:Number = 1000`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The SoundEffect class uses an internal Sound object to control the MP3 file. This property specifies the minimum number of milliseconds worth of sound data to hold in the Sound object's buffer. The Sound object waits until it has at least this much data before beginning playback, and before resuming playback after a network stall.

The default value is `1000.`

### isLoading

property

`isLoading:Boolean` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

This property is `true` if the MP3 has been loaded.

Implementation
`public function get isLoading():Boolean`

### loops

property

`public var loops:int = 0`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The number of times to play the sound in a loop, where a value of 0 means play the effect once, a value of 1 means play the effect twice, and so on. If you repeat the MP3 file, it still uses the setting of the `useDuration` property to determine the playback time.

The `duration` property takes precedence over this property. If the effect duration is not long enough to play the sound at least once, the sound does not loop.

The default value is `0.`

### panEasingFunction

property

`public var panEasingFunction:Function`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The easing function for the pan effect. Use this function to interpolate between the values of `panFrom` and `panTo`.

### panFrom

property

`public var panFrom:Number`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Initial pan of the Sound object. The value can range from -1.0 to 1.0, where -1.0 uses only the left channel, 1.0 uses only the right channel, and 0.0 balances the sound evenly between the two channels.

The default value is `0.0.`

### panTo

property

`public var panTo:Number`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Final pan of the Sound object. The value can range from -1.0 to 1.0, where -1.0 uses only the left channel, 1.0 uses only the right channel, and 0.0 balances the sound evenly between the two channels.

The default value is `0.0.`

### sound

property

`sound:Sound` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The Sound object that the MP3 file has been loaded into.

Implementation
`public function get sound():Sound`

### source

property

`source:Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The URL or class of the MP3 file to play. If you have already embedded the MP3 file, using the `Embed` keyword, you can pass the Class object of the MP3 file to the `source` property. Otherwise, specify the full URL to the MP3 file.

Implementation
`public function get source():Object`
`public function set source(value:Object):void`

### startTime

property

`public var startTime:Number = 0`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The initial position in the MP3 file, in milliseconds, at which playback should start.

The default value is `0.`

### useDuration

property

`public var useDuration:Boolean = true`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

If `true`, stop the effect after the time specified by the `duration` property has elapsed. If `false`, stop the effect after the MP3 finishes playing or looping.

The default value is `true.`

### volumeEasingFunction

property

`public var volumeEasingFunction:Function`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The easing function for the volume effect. This function is used to interpolate between the values of `volumeFrom` and `volumeTo`.

### volumeFrom

property

`public var volumeFrom:Number`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Initial volume of the Sound object. Value can range from 0.0 to 1.0.

The default value is `1.`

### volumeTo

property

`public var volumeTo:Number`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Final volume of the Sound object. Value can range from 0.0 to 1.0.

The default value is `1.`

Constructor Detail

### SoundEffect

()
Constructor

`public function SoundEffect(target:Object = null)`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Constructor.

Parameters

| `target:Object` (default = `null`)`` — The Object to animate with this effect.

Method Detail

### load

()
method

`public function load():void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Loads the MP3 if the `source` property points to a URL.

Event Detail

### complete

Event

Event Object Type: `flash.events.Event`
property Event.type = `flash.events.Event.COMPLETE`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when the sound file finishes loading.

The `Event.COMPLETE` constant defines the value of the `type` property of a `complete` event object.

This event has the following properties:

Property | Value
--- | ---
`bubbles` | `false`
`cancelable` | `false`; there is no default behavior to cancel.
`currentTarget` | The object that is actively processing the Event object with an event listener.
`target` | The network object that has completed loading.

### id3

Event

Event Object Type: `flash.events.Event`
property Event.type = `flash.events.Event.ID3`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when ID3 data is available for an MP3 sound file.

The `Event.ID3` constant defines the value of the `type` property of an `id3` event object.

This event has the following properties:

Property | Value
--- | ---
`bubbles` | `false`
`cancelable` | `false`; there is no default behavior to cancel.
`currentTarget` | The object that is actively processing the Event object with an event listener.
`target` | The Sound object loading the MP3 for which ID3 data is now available. The `target` is not always the object in the display list that registered the event listener. Use the `currentTarget` property to access the object in the display list that is currently processing the event.

### ioError

Event

Event Object Type: `flash.events.IOErrorEvent`
property IOErrorEvent.type = `flash.events.IOErrorEvent.IO_ERROR`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when an error occurs during the loading of the sound file.

Defines the value of the `type` property of an `ioError` event object.

This event has the following properties:

Property | Value
--- | ---
`bubbles` | `false`
`cancelable` | `false`; there is no default behavior to cancel.
`currentTarget` | The object that is actively processing the Event object with an event listener.
`errorID` | A reference number associated with the specific error (AIR only).
`target` | The network object experiencing the input/output error.
`text` | Text to be displayed as an error message.

### progress

Event

Event Object Type: `flash.events.ProgressEvent`
property ProgressEvent.type = `flash.events.ProgressEvent.PROGRESS`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched periodically as the sound file loads.

Within the event object, you can access the number of bytes currently loaded and the total number of bytes to load. The event is not guaranteed to be dispatched, which means that the `complete` event might be dispatched without any `progress` events being dispatched.

Defines the value of the `type` property of a `progress` event object.

This event has the following properties:

Property | Value
--- | ---
`bubbles` | `false`
`bytesLoaded` | The number of items or bytes loaded at the time the listener processes the event.
`bytesTotal` | The total number of items or bytes that ultimately will be loaded if the loading process succeeds.
`cancelable` | `false`; there is no default behavior to cancel.
`currentTarget` | The object that is actively processing the Event object with an event listener.
`target` | The object reporting progress.

Examples How to use this example
SoundEffectExample.mxml
Copy

    <?xml version="1.0"?>
    <!-- Simple example to demonstrate the SoundEffect effect. -->
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx">

        <fx:Declarations>
            <mx:SoundEffect id="mySounds" source="@Embed(source='assets/jazz.mp3')"/>
        </fx:Declarations>

        <s:Panel title="Sound Effect Example" width="75%" height="75%" >
            <s:VGroup left="20" right="20" top="20" bottom="20">

            <s:Label width="100%" color="blue"
                text="Click on the phone to hear the sound effect."/>

            <mx:Image id="flex" source="@Embed(source='assets/Nokia_6630.png')"
                mouseDownEffect="{mySounds}"/>

            </s:VGroup>
        </s:Panel>
    </s:Application>

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