API Documentation for: 0.6.0
Show:

FlashAudioSoundInstance Class

FlashAudioSoundInstance extends the base api of AbstractSoundInstance and is used by FlashAudioPlugin.

NOTE audio control is shuttled to a flash player instance via the flash reference.

Constructor

FlashAudioSoundInstance

(
  • src
  • startTime
  • duration
  • playbackResource
)

Parameters:

  • src String

    The path to and file name of the sound.

  • startTime Number

    Audio sprite property used to apply an offset, in milliseconds.

  • duration Number

    Audio sprite property used to set the time the clip plays for, in milliseconds.

  • playbackResource Object

    Any resource needed by plugin to support audio playback.

Methods

_addLooping

() protected

Inherited from AbstractSoundInstance: _addLooping:963

Available since 0.6.0

Internal function called when looping is added during playback.

_beginPlaying

(
  • offset
  • loop
  • volume
  • pan
)
Boolean protected

Called by the Sound class when the audio is ready to play (delay has completed). Starts sound playing if the src is loaded, otherwise playback will fail.

Parameters:

  • offset Number

    How far into the sound to begin playback, in milliseconds.

  • loop Number

    The number of times to loop the audio. Use -1 for infinite loops.

  • volume Number

    The volume of the sound, between 0 and 1.

  • pan Number

    The pan of the sound between -1 (left) and 1 (right). Note that pan does not work for HTML Audio.

Returns:

Boolean:

If playback succeeded.

_cleanUp

() protected

Clean up the instance. Remove references and clean up any additional properties such as timers.

_dispatchEvent

(
  • eventObj
  • eventPhase
)
protected

Parameters:

_handleCleanUp

() protected

Inherited from AbstractSoundInstance but overwritten in _handleCleanUp:1003

Available since 0.6.0

Internal function called when AbstractSoundInstance is being cleaned up

_handleSoundComplete

(
  • event
)
protected

Audio has finished playing. Manually loop it if required.

Parameters:

_handleSoundReady

() protected

Handles starting playback when the sound is ready for playing.

_handleStop

() protected

Inherited from AbstractSoundInstance: _handleStop:993

Available since 0.6.0

Internal function called when stopping playback

_interrupt

() protected

The sound has been interrupted.

_pause

() protected

Inherited from AbstractSoundInstance: _pause:973

Available since 0.6.0

Internal function called when pausing playback

_playFailed

() private

Play has failed, which can happen for a variety of reasons. Cleans up instance and dispatches failed event

_removeLooping

() protected

Inherited from AbstractSoundInstance: _removeLooping:953

Available since 0.6.0

Internal function called when looping is removed during playback.

_resume

() protected

Inherited from AbstractSoundInstance: _resume:983

Available since 0.6.0

Internal function called when resuming playback

_sendEvent

(
  • type
)
protected

A helper method that dispatches all events for AbstractSoundInstance.

Parameters:

_updateDuration

() protected

Inherited from AbstractSoundInstance but overwritten in _updateDuration:913

Available since 0.6.0

Internal function used to update the duration of the audio.

_updatePan

() protected

Inherited from AbstractSoundInstance: _updatePan:903

Available since 0.6.0

Internal function used to update the pan

_updatePosition

() protected

Inherited from AbstractSoundInstance but overwritten in _updatePosition:933

Available since 0.6.0

Internal function that calculates the current position of the playhead and sets it on this._position

_updateVolume

() protected

Internal function used to update the volume based on the instance volume, master volume, instance mute value, and master mute value.

addEventListener

(
  • type
  • listener
  • [useCapture]
)
Function | Object

Adds the specified event listener. Note that adding multiple listeners to the same function will result in multiple callbacks getting fired.

Example

 displayObject.addEventListener("click", handleClick);
 function handleClick(event) {
    // Click happened.
 }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function | Object:

Returns the listener for chaining or assignment.

destroy

()

Inherited from AbstractSoundInstance: destroy:433

Available since 0.6.0

Remove all external references and resources from AbstractSoundInstance. Note this is irreversible and AbstractSoundInstance will no longer work

dispatchEvent

(
  • eventObj
)
Boolean

Dispatches the specified event to all listeners.

Example

 // Use a string event
 this.dispatchEvent("complete");

 // Use an Event instance
 var event = new createjs.Event("progress");
 this.dispatchEvent(event);

Parameters:

  • eventObj Object | String | Event

    An object with a "type" property, or a string type. While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used, dispatchEvent will construct an Event instance with the specified type.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

getDuration

() Number

NOTE duration can be accessed directly as a property, getDuration exists to allow support for IE8 with FlashAudioPlugin.

Get the duration of the instance, in milliseconds. Note a sound needs to be loaded before it will have duration, unless it was set manually to create an audio sprite.

Example

var soundDur = myInstance.getDuration();

Returns:

Number:

The duration of the sound instance in milliseconds.

getLoop

() Number

Inherited from AbstractSoundInstance: getLoop:746

Available since 0.6.0

NOTE loop can be accessed directly as a property, getLoop exists to allow support for IE8 with FlashAudioPlugin.

The number of play loops remaining. Negative values will loop infinitely.

Returns:

getMute

() Boolean deprecated

Inherited from AbstractSoundInstance but overwritten in getMute:541

Deprecated, please use muted instead.

Returns:

Boolean:

If the sound is muted.

getPan

() Number

NOTE pan can be accessed directly as a property, getPan remains to allow support for IE8 with FlashAudioPlugin.

Get the left/right pan of the instance. Note in WebAudioPlugin this only gives us the "x" value of what is actually 3D audio.

Example

var myPan = myInstance.getPan();

Returns:

Number:

The value of the pan, between -1 (left) and 1 (right).

getPaused

() Boolean

Inherited from AbstractSoundInstance: getPaused:452

Available since 0.6.0

NOTE paused can be accessed directly as a property, and getPaused remains to allow support for IE8 with FlashAudioPlugin.

Returns true if the instance is currently paused.

Returns:

Boolean:

If the instance is currently paused

getPosition

() Number

NOTE position can be accessed directly as a property, getPosition remains to allow support for IE8 with FlashAudioPlugin.

Get the position of the playhead of the instance in milliseconds.

Example

var currentOffset = myInstance.getPosition();

Returns:

Number:

The position of the playhead in the sound, in milliseconds.

getVolume

()

NOTE volume can be accessed directly as a property, getVolume remains to allow support for IE8 with FlashAudioPlugin.

Get the volume of the instance. The actual output volume of a sound can be calculated using: myInstance.getVolume() * createjs.Sound.getVolume();

Returns:

The current volume of the sound instance.

hasEventListener

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

initialize

() deprecated protected

REMOVED. Removed in favor of using MySuperClass_constructor. See extend and promote for details.

There is an inheritance tutorial distributed with EaselJS in /tutorials/Inheritance.

off

(
  • type
  • listener
  • [useCapture]
)

Inherited from EventDispatcher: off:254

A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the .on method.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

on

(
  • type
  • listener
  • [scope]
  • [once=false]
  • [data]
  • [useCapture=false]
)
Function

Inherited from EventDispatcher: on:182

A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.

This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The created anonymous function is returned for use with .removeEventListener (or .off).

Example

    var listener = myBtn.on("click", handleClick, null, false, {count:3});
    function handleClick(evt, data) {
        data.count -= 1;
        console.log(this == myBtn); // true - scope defaults to the dispatcher
        if (data.count == 0) {
            alert("clicked 3 times!");
            myBtn.off("click", listener);
            // alternately: evt.remove();
        }
    }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [scope] Object optional

    The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).

  • [once=false] Boolean optional

    If true, the listener will remove itself after the first time it is triggered.

  • [data] optional

    Arbitrary data that will be included as the second parameter when the listener is called.

  • [useCapture=false] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function:

Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

pause

() Boolean deprecated

Deprecated, please use paused instead.

Returns:

Boolean:

If the pause call succeeds. This will return false if the sound isn't currently playing.

play

(
  • [interrupt="none"|options]
  • [delay=0]
  • [offset=0]
  • [loop=0]
  • [volume=1]
  • [pan=0]
)
AbstractSoundInstance

Play an instance. This method is intended to be called on SoundInstances that already exist (created with the Sound API createInstance or play).

Example

 var myInstance = createjs.Sound.createInstance(mySrc);
 myInstance.play({offset:1, loop:2, pan:0.5});    // options as object properties
 myInstance.play(createjs.Sound.INTERRUPT_ANY);    // options as parameters

Note that if this sound is already playing, this call will do nothing.

Parameters:

  • [interrupt="none"|options] String | Object optional

    How to interrupt any currently playing instances of audio with the same source, if the maximum number of instances of the sound are already playing. Values are defined as INTERRUPT_TYPE constants on the Sound class, with the default defined by Sound defaultInterruptBehavior.
    OR
    This parameter can be an object that contains any or all optional properties by name, including: interrupt, delay, offset, loop, volume, and pan (see the above code sample).

  • [delay=0] Number optional

    The delay in milliseconds before the sound starts

  • [offset=0] Number optional

    How far into the sound to begin playback, in milliseconds.

  • [loop=0] Number optional

    The number of times to loop the audio. Use -1 for infinite loops.

  • [volume=1] Number optional

    The volume of the sound, between 0 and 1.

  • [pan=0] Number optional

    The pan of the sound between -1 (left) and 1 (right). Note that pan is not supported for HTML Audio.

Returns:

AbstractSoundInstance:

A reference to itself, intended for chaining calls.

removeAllEventListeners

(
  • [type]
)

Removes all listeners for the specified type, or all listeners of all types.

Example

 // Remove all listeners
 displayObject.removeAllEventListeners();

 // Remove all click listeners
 displayObject.removeAllEventListeners("click");

Parameters:

  • [type] String optional

    The string type of the event. If omitted, all listeners for all types will be removed.

removeEventListener

(
  • type
  • listener
  • [useCapture]
)

Removes the specified event listener.

Important Note: that you must pass the exact function reference used when the event was added. If a proxy function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or closure will not work.

Example

 displayObject.removeEventListener("click", handleClick);

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

resume

() Boolean deprecated

Deprecated, please use paused instead.

Returns:

Boolean:

If the resume call succeeds. This will return false if called on a sound that is not paused.

setDuration

(
  • value
)
AbstractSoundInstance

Inherited from AbstractSoundInstance: setDuration:695

Available since 0.6.0

NOTE duration can be accessed directly as a property, setDuration exists to allow support for IE8 with FlashAudioPlugin.

Set the duration of the audio. Generally this is not called, but it can be used to create an audio sprite out of an existing AbstractSoundInstance.

Parameters:

  • value Number

    The new duration time in milli seconds.

Returns:

AbstractSoundInstance:

Returns reference to itself for chaining calls

setLoop

(
  • value
)

Inherited from AbstractSoundInstance: setLoop:760

Available since 0.6.0

NOTE loop can be accessed directly as a property, setLoop exists to allow support for IE8 with FlashAudioPlugin.

Set the number of play loops remaining.

Parameters:

  • value Number

    The number of times to loop after play.

setMute

(
  • value
)
Boolean deprecated

Inherited from AbstractSoundInstance but overwritten in setMute:529

Deprecated, please use muted instead.

Parameters:

  • value Boolean

    If the sound should be muted.

Returns:

Boolean:

If the mute call succeeds.

setPan

(
  • value
)
AbstractSoundInstance

NOTE pan can be accessed directly as a property, getPan remains to allow support for IE8 with FlashAudioPlugin.

Set the left(-1)/right(+1) pan of the instance. Note that HTMLAudioPlugin does not support panning, and only simple left/right panning has been implemented for WebAudioPlugin. The default pan value is 0 (center).

Example

myInstance.setPan(-1);  // to the left!

Parameters:

  • value Number

    The pan value, between -1 (left) and 1 (right).

Returns:

AbstractSoundInstance:

Returns reference to itself for chaining calls

setPlayback

(
  • value
)
AbstractSoundInstance

Inherited from AbstractSoundInstance but overwritten in setPlayback:713

Available since 0.6.0

NOTE playbackResource can be accessed directly as a property, setPlaybackResource exists to allow support for IE8 with FlashAudioPlugin.

An object containing any resources needed for audio playback, set by the plugin. Only meant for use by advanced users.

Parameters:

  • value Object

    The new playback resource.

Returns:

AbstractSoundInstance:

Returns reference to itself for chaining calls

setPosition

(
  • value
)
AbstractSoundInstance

NOTE position can be accessed directly as a property, setPosition remains to allow support for IE8 with FlashAudioPlugin.

Set the position of the playhead in the instance. This can be set while a sound is playing, paused, or stopped.

Example

 myInstance.setPosition(myInstance.getDuration()/2); // set audio to its halfway point.

Parameters:

  • value Number

    The position to place the playhead, in milliseconds.

Returns:

AbstractSoundInstance:

Returns reference to itself for chaining calls

setVolume

(
  • value
)
AbstractSoundInstance

NOTE volume can be accessed directly as a property, setVolume remains to allow support for IE8 with FlashAudioPlugin.

Set the volume of the instance.

Example

 myInstance.setVolume(0.5);

Note that the master volume set using the Sound API method setVolume will be applied to the instance volume.

Parameters:

  • value Object

    The volume to set, between 0 and 1.

Returns:

AbstractSoundInstance:

A reference to itself, intended for chaining calls.

stop

() AbstractSoundInstance

Stop playback of the instance. Stopped sounds will reset their position to 0, and calls to resume will fail. To start playback again, call play.

Example

myInstance.stop();

Returns:

AbstractSoundInstance:

A reference to itself, intended for chaining calls.

toString

() String

Inherited from EventDispatcher: toString:367

Returns:

String:

a string representation of the instance.

willTrigger

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type on this object or any of its ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the specified type is dispatched from this object, it will trigger at least one listener.

This is similar to hasEventListener, but it searches the entire event flow for a listener, not just this object.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

Properties

_captureListeners

Object protected

_listeners

Object protected

Inherited from EventDispatcher: _listeners:94

delayTimeoutId

TimeoutVariable protected

Inherited from AbstractSoundInstance: delayTimeoutId:108

Available since 0.4.0

A Timeout created by Sound when this AbstractSoundInstance is played with a delay. This allows AbstractSoundInstance to remove the delay if stop, pause, or cleanup are called before playback begins.

Default: null

duration

Number

Inherited from AbstractSoundInstance: duration:173

Available since 0.6.0

The length of the audio clip, in milliseconds.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setDuration and getDuration.

Default: 0

loop

Number public

Inherited from AbstractSoundInstance: loop:229

Available since 0.6.0

The number of play loops remaining. Negative values will loop infinitely.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setLoop and getLoop.

Default: 0

muted

Boolean

Inherited from AbstractSoundInstance: muted:249

Available since 0.6.0

Determines if the audio is currently muted.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setMute and getMute.

Default: false

pan

Number

Inherited from AbstractSoundInstance: pan:154

The pan of the sound, between -1 (left) and 1 (right). Note that pan is not supported by HTML Audio.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setPan and getPan.
Note in WebAudioPlugin this only gives us the "x" value of what is actually 3D audio.

Default: 0

paused

Boolean

Tells you if the audio is currently paused.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Use pause and resume to set.

playbackResource

Object

Object that holds plugin specific resource need for audio playback. This is set internally by the plugin. For example, WebAudioPlugin will set an array buffer, HTMLAudioPlugin will set a tag, FlashAudioPlugin will set a flash reference.

Default: null

playState

String

The play state of the sound. Play states are defined as constants on Sound.

Default: null

position

Number

Inherited from AbstractSoundInstance: position:210

Available since 0.6.0

The position of the playhead in milliseconds. This can be set while a sound is playing, paused, or stopped.


Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower, Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setPosition and getPosition.

Default: 0

src

String

Inherited from AbstractSoundInstance: src:84

The source of the sound.

Default: null

uniqueId

String | Number

The unique ID of the instance. This is set by Sound.

Default: -1

volume

Number

The volume of the sound, between 0 and 1.
Note this uses a getter setter, which is not supported by Firefox versions 3.6 or lower and Opera versions 11.50 or lower, and Internet Explorer 8 or lower. Instead use setVolume and getVolume.

The actual output volume of a sound can be calculated using: myInstance.volume * createjs.Sound.getVolume();

Default: 1

Events

complete

Inherited from AbstractSoundInstance: complete:323

Available since 0.4.0

The event that is fired when playback completes. This means that the sound has finished playing in its entirety, including its loop iterations.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

failed

Inherited from AbstractSoundInstance: failed:305

Available since 0.4.0

The event that is fired when playback has failed. This happens when there are too many channels with the same src property already playing (and the interrupt value doesn't cause an interrupt of another instance), or the sound could not be played, perhaps due to a 404 error.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

interrupted

Inherited from AbstractSoundInstance: interrupted:296

Available since 0.4.0

The event that is fired when playback is interrupted. This happens when another sound with the same src property is played using an interrupt value that causes this instance to stop playing.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

loop

Inherited from AbstractSoundInstance: loop:315

Available since 0.4.0

The event that is fired when a sound has completed playing but has loops remaining.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

succeeded

Inherited from AbstractSoundInstance: succeeded:288

Available since 0.4.0

The event that is fired when playback has started successfully.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.