Home / Articles / Adobe Flash / 10 Minutes with Flash: ActionScript You'll Never Have to Write Again

10 Minutes with Flash: ActionScript You'll Never Have to Write Again

Contents

  1. Card-Carrying Code Hater (Sort of)
  2. Portable Scripting
  3. Putting Your Hard Work to Good Use

Article Description

Robert Hoekman, Jr. is just as tired of writing code as you are, so he offers up some timely tips on storing ActionScript and loading it on-the-fly in this fourth installment of "10 Minutes with Flash."

Let it be known from here on out that I don't really like writing code. I like to do things visually, and the various programming languages I have to deal with on a daily basis aren't exactly the most exciting aspect of my workload. I write code, I understand it, and I love exploring the possibilities of what it can do. I just don't like looking at it. I often wonder, in fact, how the super-geeks of the world manage to stare at line after line of code all day long without offing themselves by shoving their own heads through their monitors.

Card-Carrying Code Hater (Sort of)

That being said, Macromedia has been kind enough to provide guys like me with a way out of some of the monotony. With ActionScript, there are all sorts of options for reusing code. You can write scripts as class files and simply create instances of them in your project. You can write functions and call back to them whenever you need to. You can also write up a script and include it in your project via an #include command, which is what you'll do today. This project involves writing a generic script, so you never have to remember the syntax for anything, and pulling it into your project on-the-fly, calling up its methods and taking a nap.

In this article, the fourth in the series "10 Minutes With Flash," you'll create an instance of the MovieClipLoader class to handle loading assets into a movie at runtime, save it as an external file, and then include it in a movie—enabling you to load anything you want using one line of code instead of 20. If you're familiar with the MovieClipLoader class, you'll know that arguably the best use for it is as a preloader, using the onLoadProgress method to trigger some sort of progress bar animation or percentage text, For this article, however, you'll just write a generic script you can modify later.

NOTE

I've provided completed versions of the files for this article here. (Take special note of the image.jpg file. It's a picture of me, underwater, having the time of my life. My wife took this photo while on our last vacation. I added a lovely purple hue because, well, I was in a purple mood this morning.)

Check out Figure 1 to see what you'll be doing.

Figure 1Figure 1 Our hero has managed to save his breath for once.

2. Portable Scripting | Next Section