NOTICE: ActionScipt No Longer Supported

These blog posts are for ActionScript, which is a programming language for Adobe Flash Player. Unfortunately, Adobe Flash is no longer supported for web applications, so this information is likely not very useful to most developers. We are keeping it for those who still enjoy ActionScript and for posterity. We named our company after it, after all.

ActionScript

Tutorial – Flash ActionScript – Advanced Path

Leave a Reply

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!

Leave a Reply

Your email address will not be published. Required fields are marked *