Website Designers and Webmasters

Dedicated to all the tasks Webmasters, Website Developers and Website Designers find themselves facing.

By: Ashton Sanders

Tutorial – Flash ActionScript – Advanced Path

Mar 19 2007

Filed under: Flash ActionScript

Yesterday, I learned how to do two advanced things with paths in Flash ActionScript.

For an introduction, I’m creating a flash animation that will calculate a loan. What many people don’t know about loans is that someone can choose to decrease the rate on their loan in exchange for increased closing costs. I’m making a Flash Animation that will allow you to do that. It will also allow you to select different types of loans, (which will change your interest rate, and closing costs).

In this Flash Animation, I had an ActionScript function that was called from many different movies, and I need to use a lot of variables to make sure it reacted differently to every request.

Here are the things I learned:

Creating Variables From Paths

My ActionScript Function call was simple.

On (rollover) {
function(this);
}

Then all I needed to to was take the path to “this” and break it up into variables so that my Flash ActionScript will be able to do different things for each request. This seemed simple enough, I thought I could use the ActionScript Function split(.) to break apart the path into 4 different variables and thus allow me to do different things for each request. Unfortunately, what is returned by “this” is not a string so you can’t split it… or do anything else that would work on a string. But you can do this:

function(path){
path2 = path._parent._parent._name;
path3 = path._parent._name;
path4 = path._name;
}

And that will give you the name of every Flash Movie Clip in your path in the form of a string! That is a very useful Flash Action Script technique, but it lead me to the next problem:

Using Variables in Paths:

Lets say that within your Flash Animation you have movieClipB inside of movieClipA. You also have a variable in movieClipB called “num”;

The ActionScript path to reach var num from the root is:

_root.movieClipA.movieClipB.num

But what if you need to use a variable in a path. (This could occur if you have multiple movies all using the same function.)I thought this would work.. but it doesn’t:

path1 = “movieClipA”;
_root.path1.movieClipB.num;

But the above ActionScript does NOT work. However this does work:

movieroot = “_root”;
path1 = “movieClipA”;
movieroot[path1].movieClipB.num;

That is how you use variables in a path!

By: Ashton Sanders

Tutorial – Flash ActionScript – Path

Mar 17 2007

Filed under: Flash ActionScript

Animating with Flash is great! It’s the most fun you can have while making a website. But a flash animation doesn’t become interactive without ActionScript.

ActionScript Allows you to send orders to many different sections of your flash animation. Any Flash Animation can have hundreds of different movie clips graphics and buttons. A Flash Movie Clip, Flash graphic or Flash button can be within other Flash Movie Clips or graphics. This Can create a very complicated system of Flash Graphics, Movie Clips and Buttons.

If you look at it like a folder system, it becomes easier to understand. Lets Say movieClipA and movieClipB are inside movieClipC (And those are their names respectively.) This is what the hierarchy would look like:

  • movieClipC
    • movieClipA
    • movieClipB

To send an order to movieClipB (like to stop) this would be your command:

_root.movieClipC.movieClipB.stop();

What is this “_root.” thing?
This first section is where you are starting the command at. “_root.” tells the command to go to the very first level of your flash movie. To compare this to a Windows machine, this is like telling your computer to go all the way back to “C:\”. Then we have the name of the first movie (movieClipC), and then the name of the second movie (movieClipB). Then Finally we have the command to stop (stop();).

More to come soon,
-Ashton Sanders

« Newer Posts
RSS

Where Am I?

You have found the semi-coherent ramblings of Ashton Sanders: a website designer, developer and webmaster. This is primarily Ashton's place to save notes about techniques and things that he learns in his never-ending conquest of the internet. Hopefully it's coherent enough to be useful to you too.

Subscribe:

Enter your email to get automatic emails whenever Ashton posts on the blog.

Email:

Advertisers:

Email Marketing $19/Month! OIOpublisher Learn how to make Money from Blogging Hillarious, High-Quality Shirts for $6/each Great Book Keeping and Invoicing Software Advertiser Here

Tags and Categories

Links

Blog Roll