Written by: Jesse Stratford
Difficulty Level: Beginner
Requirements: Flash 5 or higher.
Topics Covered: Paths.
There is no source file for this tutorial.

This tutorial deals with referencing objects in Flash via paths.

I decided to write this tutorial on day after answered what must be the millionth question which can be solved by investigating paths. This guy had a problem where his movie worked fine until he loaded it up inside another, on Level 1, at which point none of his buttons did as they were told and all his text fields died. In this tutorial we will discuss how Flash uses paths to keep track of objects and how we can use them to reference objects within our Flash files. While I will be talking about variables, you don't need to know any programming to complete this tutorial. This tutorial does not deal with animation along paths (or "Guides"), that is a completely different topic.

A path in Flash is analogous to a 'path' in a park; it's a way of getting from one place to another. A path in Flash directs Flash's interpreter to a specific object within the movie. Paths are vital to your understanding of Actionscript because ,without paths your entire SWF contents would have to reside in one place (on one level for instance), which is increasingly impossible with the fancy stuff designers and developers are doing these days.

Paths to objects.

An Object in Flash can be pretty much anything. Common Objects include MovieClips, Buttons and TextField but those of you who understand Object Oriented Programming will know that Objects in Flash are much more universal than these few examples. For this tutorial however, these few examples will suffice. While you're a beginner, paths are probably most applicable in terms of Buttons and Movie Clips, and using paths to reference more advanced Objects works just the same, so we will focus on these objects to begin with.

Imagine you have a movie clip on your main stage, called 'clip1' for example. Within this clip is another clip called 'clip2'. This hierarchical (level based) layout is great for games and navigation, and very common. Now imagine you have a button on the main stage also. When the button is clicked you want it to perform an action on 'clip2', (which action is not important, we'll use a visibility set in our example). Selecting your button you add the actions as follows:

on (release) {
          setProperty ("clip2", _visible, false);
          // OR
          clip2._visible = false;
  }
Now you test your movie, hit your button and Wham!... Nothing happens.

Once you're over the initial shock you go back to your code and, scratching your head, wonder what you've done wrong. Thinking back to our example, recall that is on the main stage and it contains , (see picture, left).


Now, since contains , does not actually reside on the main timeline does it? No, it doesn't. It is on the timeline within the Movie Clip. We all know this, but Flash doesn't, so we have to tell it using paths in our syntax.

The table below shows the path syntax parameters and gives examples of how to use them. We go into more detail over the page so just take a look to begin with then we'll describe how it works.

Parameter Usage What it tells Flash
_level0 setProperty ("_level0"
"We're going right back to the lowest Level of the movie".

_root setProperty ("_root"
"We're going right to the bottom of the current Level; to the Main Stage on which our base Objects are stored."

When you get into loading separate SWF files into Levels, _root will refer to the base of the current level, while specifying a Level using the syntax shown above will allow you select a specific Level. If this is unclear to you, just ignore it. It will become clear if you ever load content into other Levels, which is becoming increasingly less common practice nowadays.

. (dot) setProperty ("_root.clip1.clip2"
"Whatever comes after this dot further defines the path to something." In this case, is on the timeline of which is on the _root.
But wait, there's more, turn the page and read on!