![]() |
| News Documentation Tutorials Extensions Download Forum Contact |
|
•
Overview •
API Index »
Tutorials |
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 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
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 /: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 "_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
Target Paths to Movies loaded in multiple Flash Player Instances
(Advanced!) 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. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||