FlashPlugin Class
Play sounds using a Flash instance. This plugin is not used by default, and must be registered manually in Sound using the registerPlugins method. This plugin is recommended to be included if sound support is required in older browsers such as IE8.
This plugin requires FlashAudioPlugin.swf and swfObject.js (which is compiled into the minified FlashPlugin-X.X.X.min.js file. You must ensure that BASE_PATH is set when using this plugin, so that the script can find the swf.
Example
createjs.FlashPlugin.BASE_PATH = "../src/SoundJS/";
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.HTMLAudioPlugin, createjs.FlashPlugin]);
// Adds FlashPlugin as a fallback if WebAudio and HTMLAudio do not work.
Note that the SWF is embedded into a container DIV (with an id and classname of "SoundJSFlashContainer"), and will have an id of "flashAudioContainer". The container DIV is positioned 1 pixel off-screen to the left to avoid showing the 1x1 pixel white square.
Known Browser and OS issues for HTML Audio
All browsers
- There can be a delay in flash player starting playback of audio. This has been most noticeable in Firefox. Unfortunely this is an issue with the flash player and therefore cannot be addressed by SoundJS.
Constructor
FlashPlugin
()
Item Index
Methods
- create
- flashLog
- generateCapabiities static
- getVolume
- handleErrorEvent
- handleEvent
- handleFlashReady
- handlePreloadEvent
- handleSoundEvent
- handleSWFReady
- handleTimeout
- init
- isPreloadStarted
- isSupported static
- preload
- register
- registerPreloadInstance
- registerSoundInstance
- removeAllSounds
- removeSound
- setMute
- setVolume
- unregisterPreloadInstance
- unregisterSoundInstance
- updateVolume
Properties
Methods
create
-
src
Create a sound instance. If the sound has not been preloaded, it is internally preloaded here.
Parameters:
-
src
StringThe sound source to use.
Returns:
flashLog
-
data
Used to output traces from Flash to the console, if FlashPlugin/showOutput is
true
.
Parameters:
-
data
StringThe information to be output.
generateCapabiities
()
protected
static
Determine the capabilities of the plugin. Used internally. Please see the Sound API getCapabilities method for an overview of plugin capabilities.
getVolume
()
Get the master volume of the plugin, which affects all SoundInstances.
Returns:
handleErrorEvent
-
error
Handles error events from Flash. Note this function currently does not process any events.
Parameters:
-
error
StringIndicates the error.
handleEvent
-
method
Handles events from Flash intended for the FlashPlugin class. Currently only a "ready" event is processed.
Parameters:
-
method
StringIndicates the method to run.
handleFlashReady
()
protected
The Flash application that handles preloading and playback is ready. We wait for a callback from Flash to ensure that everything is in place before playback begins.
handlePreloadEvent
-
flashId
-
method
Handles events from Flash and routes communication to a Loader
via the Flash ID. The method
and arguments from Flash are run directly on the sound loader.
handleSoundEvent
-
flashId
-
method
Handles events from Flash, and routes communication to a SoundInstance via the Flash ID. The method and arguments from Flash are run directly on the sound instance.
handleSWFReady
-
event
The SWF used for sound preloading and playback has been initialized.
Parameters:
-
event
ObjectContains a reference to the swf.
handleTimeout
()
protected
The callback when Flash does not initialize. This usually means the SWF is missing or incorrectly pathed.
init
()
protected
An initialization function run by the constructor
isPreloadStarted
-
src
Checks if preloading has started for a specific source. If the source is found, we can assume it is loading, or has already finished loading.
Parameters:
-
src
StringThe sound URI to check.
Returns:
isSupported
()
Boolean
static
Determine if the plugin can be used in the current browser/OS.
Returns:
preload
-
src
-
instance
-
basePath
Preload a sound instance. This plugin uses Flash to preload and play all sounds.
register
-
src
-
instances
Pre-register a sound instance when preloading/setup. Note that the FlashPlugin will return a Loader instance for preloading since Flash can not access the browser cache consistently.
Parameters:
Returns:
registerPreloadInstance
-
flashId
-
instance
Used to couple a Flash loader instance with a Loader
instance
Parameters:
-
flashId
StringUsed to identify the Loader.
-
instance
LoaderThe actual instance.
registerSoundInstance
-
flashId
-
instance
Used to couple a Flash sound instance with a SoundInstance.
Parameters:
-
flashId
StringUsed to identify the SoundInstance.
-
instance
LoaderThe actual instance.
removeAllSounds
-
src
Remove all sounds added using register. Note this does not cancel a preload.
Parameters:
-
src
StringThe sound URI to unload.
removeSound
-
src
Remove a sound added using register. Note this does not cancel a preload.
Parameters:
-
src
StringThe sound URI to unload.
setMute
-
value
Mute all sounds via the plugin.
Parameters:
Returns:
setVolume
-
value
Set the master volume of the plugin, which affects all SoundInstances.
Parameters:
-
value
NumberThe volume to set, between 0 and 1.
Returns:
unregisterPreloadInstance
-
flashId
Used to decouple a Loader
instance from Flash.
Parameters:
-
flashId
StringUsed to identify the Loader.
unregisterSoundInstance
-
flashId
-
instance
Used to decouple a SoundInstance from Flash. instance.
Parameters:
-
flashId
StringUsed to identify the SoundInstance.
-
instance
LoaderThe actual instance.
Properties
audioSources
Object
protected
An object hash indexed by ID that indicates if each source is loaded or loading.
BASE_PATH
String
static
The path relative to the HTML page that the FlashAudioPlugin.swf resides. Note if this is not correct, this plugin will not work.
Default: src/SoundJS
capabilities
Object
static
The capabilities of the plugin. This is generated via the WebAudioPlugin/generateCapabilities method. Please see the Sound getCapabilities method for a list of available capabilities.
container
HTMLDivElement
protected
A reference to the DIV container that gets created to hold the Flash instance.
CONTAINER_ID
String
protected
The id name of the DIV that gets created for Flash content.
Default: flashAudioContainer
flashInstances
Object
protected
A hash of SoundInstances indexed by the related ID in Flash. This lookup is required to connect sounds in JavaScript to their respective instances in Flash.
flashPreloadInstances
Object
protected
A hash of Sound Preload instances indexed by the related ID in Flash. This lookup is required to connect a preloading sound in Flash with its respective instance in JavaScript.
flashReady
Boolean
Determines if the Flash object has been created and initialized. This is required to make ExternalInterface
calls from JavaScript to Flash.
Default: false
preloadInstances
Object
protected
A hash of Sound Preload instances indexed by the src. This lookup is required to load sounds if internal preloading is tried when flash is not ready.
queuedInstances
Object
protected
An array of Sound Preload instances that are waiting to preload. Once Flash is initialized, the queued instances are preloaded.
showOutput
Boolean
A developer flag to output all flash events to the console (if it exists). Used for debugging.
createjs.Sound.activePlugin.showOutput = true;
Default: false
WRAPPER_ID
String
protected
The id name of the DIV wrapper that contains the Flash content.
Default: SoundJSFlashContainer