FlashSound API sonify sites with Flash
News           Documentation           Tutorials           Extensions           Download           Forum           Contact

• Overview
• New in this Version

API Index
• Static Methods
• Static Properties
» Instance Methods
• Instance Properties

• Tutorials
• Compatibility
• Version History
• License
• Logic Flow chart

DocumentationInstance Methods

Instance Methods can only be used after creating an instance of the FlashSound( ) constructor function. In FSAPI version 2, native JavaScript methods that resemble ActionScript methods are named according to the ActionScript method. The older naming, starting with T, is still supported but depreciated.

Many of the instance methods in the native Flash JavaScript API and the FlashSound API start with the letter "T". This refers to "target". These methods have, as one of the arguments, a target path in slash syntax.

customEmbedSWF(embedStr,true|false)
Arguments

embedStr - list of embed attributes (required)
String type.

The second argument, defaults to true, causes the method to return the embed string. Not required.

Description

Conditionally writes out object/embed tags for SWF if browser has minimum player and player is interactive. The embedStr argument is required for this method. This JavaScript statement must be placed within the body of the html document. Use this method to embed a SWF with any combination of embed attributes and object parameters for interactive control. The default embed settings for this method are listed below.

WIDTH = 1, HEIGHT = 2
NAME and ID = instance.playerID
SWLIVECONNECT = true
PLAY = true, LOOP = true
QUALITY = low, WMODE = transparent
BGCOLOR = web page bgcolor attribute

Example

<head>
<script src="flashsound.js"></script>
<script>
var mysound = new FlashSound( );
</script>
</head>

<body>
web page content........
<script>
mysound.customEmbedSWF(
  'SRC="player.swf" WIDTH=100 HEIGHT=50 ' +
  'WMODE="Opaque" BGCOLOR="#000000" ' +
  'QUALITY="high"'

);

</script>
</body>

Notes

If you embed a graphical SWF be sure to include appropriate values for QUALITY, WMODE and BGCOLOR. The default values for these attributes are intended for hidden SWF and should be altered so graphical SWF display properly.

Use the second argument for debugging purposes or for printing HTML containing object/embed to a window using JavaScript.


embedSWF(srcURL,true|false)
Arguments

srcURL - url of swf to be embedded (required)
String type.

The second argument, defaults to true, causes the method to return the embed string. Not required.

Description

Conditionally writes out object/embed tags for hidden "sound only" swf if browser has minimum player and player is interactive. The srcURL argument is required for this method. This JavaScript statement must be placed within the body of the html document and preferably just before the closing body tag. Use this method to embed a hidden sound only SWF for interactive control. The default embed settings for this method are listed below.

WIDTH = 1, HEIGHT = 2
NAME and ID = instance.playerID
SWLIVECONNECT = true
PLAY = true, LOOP = true
QUALITY = low, WMODE = transparent
BGCOLOR = web page bgcolor attribute

Example

<head>
<script src="flashsound.js"></script>
<script>
var mysound = new FlashSound( );
</script>
</head>

<body>
web page content........
<script>
mysound.embedSWF("somepath/some.swf");
</script>
</body>

Notes Use the second argument for debugging purposes or for printing HTML containing object/embed to a window using JavaScript.

getAttributeValue(attributeName)
Arguments attributeName - name of attribute (required)
String type.
Returns string value of attribute or null if attribute is unassigned or has a blank value.
String type or null object
Description

Returns the value associated with the given embed attribute.

Example

mysound.getAttributeValue("SRC");


gotoAndPlay(target,frame) or TGotoAndPlay(target,frame)
Arguments

target - path and timeline name of target timeline using "slash" syntax. (Required)
String type.

frame - frame number(integer) or label(string) where playback is to start (required)
Integer or String type.

Description

Moves playhead to frame number or label of target timeline and starts playback at that point. Target timeline names use the "slash" syntax common to pre-ECMA ActionScript. Use "/" to specify the main timeline (parent). Frame numbering starts with 1 for this method, unlike native flash JavaScript API which starts frame numbering at 0.

Example

mysound.gotoAndPlay("/sometimeline",5)

The above javascript is equivalent to the following actionscript.

on (release) {
  sometimeline.gotoAndPlay(5);
}

Notes Unlike its ActionScript counterpart, this method will ignore stop() actions in the starting frame and play through to to the next frame. In the example above the Flash player will play frame 5 and continue to frame 6, or frame 1 if frame 5 is last frame of the timeline, regardless if there is a stop() action in frame 5.

gotoAndStop(target,frame) or TGotoAndStop(target,frame)
Arguments

target - path and timeline name of target timeline using "slash" syntax. (Required)
String type.

frame - frame number(integer) or label(string) where playback is to start (required)
Integer or String type.

Description

Moves playhead to frame number or label of target timeline, executes contents of this frame and stops. Target timeline names use the "slash" syntax common to pre-ECMA ActionScript. Use "/" to specify the main timeline (parent). Frame numbering starts with 1 for this method, unlike native flash JavaScript API which starts frame numbering at 0.

Example

mysound.gotoAndStop("/sometimeline",5)

The above javascript is equivalent to the following actionscript.

on (release) {
  sometimeline.gotoAndStop(5);
}

Notes Flash will not re-execute a frame after a gotoAndStop() call. You must explicitly move the playhead to a new frame before Flash can re-execute a frame. In the above example, you must move the playhead to a new frame before being able to re-execute frame 5.

isPlayerReady( )
Arguments n/a
Returns

true | false
Boolean type.

Description

Returns true if the following are true. Otherwise returns false.

  1. FlashSound.engage = true
  2. Browser recognizes object/embed DOM node
  3. Browser recognizes PercentLoaded( ) method
  4. PercentLoaded > 0

Use this method to check that the player is ready for native Flash JavaScript API calls to prevent error messages. All FlashSound API instance methods check that isPlayerReady( ) is true before executing. Consequently isPlayerReady( ) is only for use with native Flash JavaScript API methods not currently supported by the FSAPI.

See the playerID instance property for an example of using the isPlayerReady( ) method to determine if player is ready for script control before calling a flash javascript API method.


IsPlaying( )
Arguments n/a
Returns true | false
Boolean type.
Description

Returns true if the playhead is moving and false if the playhead is stopped. IsPlaying( ) checks for a moving playhead, not for play state of sounds set to event or start sync, or Flash 5+ sound objects.

To use with event/start sync sounds, add enough frames to the timeline so that the playhead moves on the timeline for approximately the same duration as the play length of the event/start sound.

Example

if(!theme.IsPlaying( )) {
  uisounds.TGotoAndPlay('/target','label');
}

This example prevents the uisounds instance from playing while the theme is playing.


LoadMovie(layerNumber, url)
Arguments

layerNumber- number representing layer to receive external swf (required)
Integer type.

url- url of swf to be loaded into the player. (required) String type.

Description

Loads the movie identified by url into the layer specified by layerNumber. This method does not support loading swf into targeted movie clips or setting variables like the loadMovie actionscript statement. Also its arguments are not in the same order as the loadMovie ActionScript. Use the LoadMovieNum( ) JavaScript method instead of this method.

Netscape resolves relative urls for both the LoadMovie method and the loadMovie action relative to the BASE attribute.

Example

mysound.LoadMovie(1, "some.swf");

Notes When a new movie loads in the player, it automatically loops regardless of the value for the LOOP embed attribute. To prevent automatic looping of a newly loaded SWF, place a stop action on the root timeline of this SWF.
Bug

Opera 6 Windows does not support this method. See tutorial on JavaScript/ActionScript interaction for workaround.

ActiveX Control will not load SWF into _level 0 if current SWF and SWF to load are the same.


loadMovieNum(url,layerNumber) or LoadMovieNum(url,layerNumber)
Arguments

layerNumber- number representing layer to receive external swf (required)
Integer type.

url- url of swf to be loaded into the player. (required) String type.

Description

Loads the movie identified by url into the layer specified by layerNumber. Behaves exactly like the loadMovieNum ActionScript function.

Netscape resolves relative urls for this method and the loadMovieNum action relative to the base embed property.

Example

mysound.loadMovieNum("some.swf",1);

Notes

To avoid confusion, use this javascript method, instead of the LoadMovie JavaScript method, because it behaves just like an ActionScript behavior.

When a new movie loads in the player, it automatically loops regardless of the value for the LOOP embed attribute. To prevent automatic looping of a newly loaded SWF, place a stop action on the root timeline of this SWF.

Bug

Opera 6 does not support this method. See tutorial on JavaScript/ActionScript interaction for workaround.

ActiveX Control will not load SWF into _level 0 if current SWF and SWF to load are the same.


monitorLoadProgress( )
Arguments n/a
Description

Starts a setInterval loop to repeatedly poll the PercentLoaded() method every 100 ms until PercentLoaded() returns 100. Terminates setInterval loop after load is complete.

Repeatedly executes Executes onLoadChange and onLoadComplete callback functions until SWF completely loaded.

Example <script>
mysound.monitorLoadProgress(); // start loop
mysound.embedSWF("urlto.swf");
</script>
Notes

To be used in conjunction with onLoadChange and onLoadComplete call back events.

Only able to track load progress of initially embedded or SWF loaded in _level0 with loadMovieNum().


onLoadChange(percent)
Returns current value of PercentLoaded()
Description

Callback method that executes code for each change in value PercentLoaded(). Assign a custom function to the onLoadChange() callback method to display HTML based load progress messages.

Example mysound = new FlashSound();
function customFunction(percent){
  //code to display load progress message
}
// execute customFunction for each change
// in PercentLoaded()
mysound.onLoadChange = customFunction;
Notes Will not execute until called from monitorLoadProgress().

onLoadComplete()
Returns n/a
Description

Callback method that executes code when SWF is completely loaded. Assign a custom function to the onLoadComplete() callback method to execute JavaScript when a SWF is completely loaded.

Example

mysound = new FlashSound();
function customFunction(percent){
  //code to execute when load is complete
}
// execute customFunction when PercentLoaded() is
// 100

mysound.onLoadComplete = customFunction;

Notes Will not execute until called from monitorLoadProgress().

PercentLoaded( )
Arguments n/a
Returns Integer with range of 0 - 100
Description

Returns the percent of the embedded swf loaded into the player. Values are 0 - 100 represented as Integer.

Example if (mysound.PercentLoaded() == 100) {
  mysound.gotoAndPlay("/sound", "start")
}
Notes Flash will restart PercentLoaded( ) for any new SWF loaded into _level 0, but not any other level.

play(target) or TPlay(target)
Arguments

target - path and timeline name of target timeline using "slash" syntax. (Required)
String type.

Description

Starts the playhead moving on the target timeline at the frame where playhead last stopped or first frame. Target timeline names use the "slash" syntax common to pre-ECMA ActionScript. Use "/" to specify the main timeline (parent). TPlay is equivalent to the play ActionScript statement. It begins playback at frame 1 of given timeline or at the frame where playback was last stopped with the TStopPlay( ) method.

TPlay( ) defaults to the root timeline if no target path is specified.

Example

<a href="javascript://"
  onClick='mysound.play("/"); return false'>Play a stream sound</a>


stop(target) or TStopPlay(target)
Arguments

target - path and timeline name of target timeline using "slash" syntax. (Required)
String type.

Description

Stops playhead on the timeline specified. Target timeline names use the "slash" syntax common to pre-ECMA ActionScript. Use "/" to specify the main timeline (root). TStopPlay is equivalent to the stop ActionScript statement and will only stop playback of sounds set to stream sync. TStopPlay does not stop playback of sounds set to event or start sync.

TStopPlay( ) defaults to the root timeline if no target path is specified.

Example

<a href="javascript://"
  onClick='mysound.stop("/"); return false'>Stop a stream sound</a>

Copyright © 2003 Hayden Porter, All rights reserved.