Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Paths to Objects and Variables

Paths to Objects and Variables

By Jesse Stratford | Published 09/9/2005 | Beginner | Rating:
Jesse Stratford
Jesse lives and works in Melbourne Australia. He is the Cofounder and a Director of http://ActionScript.org. A Flash enthusiast, teacher, author, freelancer and speaker Jesse enjoys participating in the http://ActionScript.org community and the wider Flash scene when he has time. 

View all articles by Jesse Stratford
Page 1 of 2
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!


Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Comments
  • Comment #1 (Posted by kim akinta - kakinta at aapt,net.au)
    Rating
    This was my 2nd tut in actionscript - I am a graphics student at Bris nth tafe - intermediate web design. You make sense - thanks I do have beg XHTML & CSS.

    My suggestion is a visual graphic of the metaphors you used - 'boxes' for variables and a 'path in a park' for paths - simple in illustrator.

    Again thanks you are clear and understandable.

    Kim Akinta
    Deagon Brisbane.
     
  • Comment #2 (Posted by Kevin Feeman - ksfeeman at yahoo.com)
    Rating
    Again, another great tutorial, learned about paths! this series is awsome, can't wait to get through the basics then onto the intermediate and advanced. Great job!
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.