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

DocumentationTutorials

Understanding Slash Syntax

An individual Flash movie (swf) consists of a root timeline (main timeline) and movie clips which are sub "timelines" attached to the root timeline or nested within movie clips. In addition, the Flash player can load multiple swf which can interact with each other. In order to create interaction, you indicate which timeline or movie clip to interact with by using a target path.

A target path tells the Flash player which timeline or movie clip to control and where it is located within the Flash player. Target paths are also used to access variables inside of movie clips. Flash supports two syntax for creating target paths. The new and preferred syntax is ECMA "dot" syntax common to object oriented languages. However, Flash also supports its own proprietary "slash" syntax which is supported by Flash 3 - 4 and is also the preferred syntax for use with the native Flash JavaScript API. Consequently, to use the FlashSound API effectively, you should understand "slash" syntax.

Note: It is possible to use ECMA dot syntax with Flash JavaScript methods in Flash 5+ but this syntax has a reputation to be not as reliable as the original slash syntax, especially for setting or getting the value of variables.

Slash Syntax
"Slash" syntax is much like root relative url syntax. A root relative url indicates that a directory or file is within the root directory. For example, the root relative url "/home.html" indicates that the html document "home" is located within the root directory. The forward slash "/" means root directory. You can link to this url from anywhere in a directory structure and the server will know to start at the root directory and work its way down.

In Slash syntax, the root timeline of a swf is similar to the root directory of a url. Movie clips are similar to subdirectories of the root timeline. The root timeline of a swf is represented by a "/" slash. Movie clips are represented by their instance name. If a movie clip with the instance name, "mymc", is attached to the root timeline its target path would be "/mymc". Unlike movie clips a root timeline does not have an instance name. In slash syntax the target path for a root timeline is always "/".

For movie clips attached to the root timeline, the forward slash is implied and you can leave it out. For example you can reference a mc, with instance name "mymc" attached to the main timeline, simply as "mymc" rather than "/mymc" from JavaScript.

Example Structure of One SWF loaded into a Flash Player

Loaded SWF Movie Clips
  FlashSound API Target Path
root timeline
( _level0)
      TGotoAndPlay("/", label)
--> mymc    

TGotoAndPlay("/mymc", label)
or
TGotoAndPlay("mymc",lablel)

  --> anothermc   TGotoAndPlay("/mymc/anothermc", label)
or
TGotoAndPlay("mymc/anothermc", label)

Typically, when working with the FlashSound API, you will only have one swf loaded in a Flash player. Most of the time you only deal with simple target paths which reference the main timeline "/" or movie clips attached to the main timeline, such as "/mymc" or "mymc" without the forward slash. However, in some cases you may need to do something more advanced such as load another SWF into a level of the player or access the values of variables within the timeline hierarchy.

Target Paths to Variables
In addition to using target paths to control playback of timelines and movie clips, you can also use target paths to get or set the value of a variable within a flash movie. Slash syntax uses the colon character ":" followed by the variable name to represent a variable. For example, to get the value of a variable named "myvar", that is declared on the root timeline the target path would be:

/:myvar

The target path to the variable, "myvar", that is declared in a movie clip, "mymc" that is attached to the main timeline would be:

/mymc:myvar

The syntax is to attach the ":" plus variable name to the end of your target path. To get or set variables with the FlashSound API, use the getVariable( ) and setVariable( ) methods which are part of the flashsound-actionscript.js extension.

Target Paths to Other Movies
Slash syntax uses "levels" to reference movie clips or the root timeline of other SWF loaded in the Flash player. Each SWF loaded into the Flash player has its own level. The first swf loaded into the player with the embed statement is loaded in level 0. All other SWF loaded with the loadMovie( ) method or action are loaded into another level of your choosing. In slash syntax a level is represented by the underscore character first "_" followed by the word "level" and the level number followed by the forward slash. The forward slash indicates that this is the root timeline of the SWF you loaded.

"_levelN/", where N represents the number of the level that the movie is loaded on.

To control the main timeline of a swf loaded into level 3 of the Flash player, the correct target path in slash syntax would be:

"_level3/"

To control a movie clip, with the instance name "mymc", attached main timeline of a swf loaded into level 3, the correct target path in slash syntax would be:

"_level3/mymc"

If your target path does not specify a level and only includes the forward slash "/", javascript assumes you intend the movie loaded in _level0. This is a little different from regular flash actionscript. In regular flash actionscript "/" is the root timeline of the current movie. However, since JavaScript is outside of the Flash player, it defaults to "/" as being the same as "_level0".

Example Structure of Multiple SWF loaded into One Flash Player Instance

Loaded SWF Movie Clips
  FlashSound API Target Path
root timeline
( _level0)
      TGotoAndPlay("/", label)
--> mymc     TGotoAndPlay("/mymc", label)
  --> anothermc   TGotoAndPlay("/mymc/anothermc", label)
         
root timeline
( _level1)
      TGotoAndPlay("_level1/", label)
--> mc1a     TGotoAndPlay("_level1/mc1a", label)
  --> mc1b   TGotoAndPlay("_level1/mc1a/mc1b", label)
--> mc2     TGotoAndPlay("_level1/mc2", label)
         
root timeline (_level22)       TGotoAndPlay("_level22/", label)

Target Paths to Movies loaded in multiple Flash Player Instances (Advanced!)
In some advanced situations you may need to have one Flash player instance control another. This is accomplished by using an FSCommand in one player to call upon the TGotoAndPlay( ) method of another player instance. For example the following FSCommand controls playback of a movie clip within a swf loaded into another Flash player instance.

fscommand ("sfx.TGotoAndPlay", "'_level1/mc1a','start'")

This FSCommand tells the FlashSound API player instance "sfx" to find the movie clip mc1a attached to the _level1 timeline.

Copyright © 2003 Hayden Porter, All rights reserved.