Actionscript

Written by Amanda Kern

Why learn actionscript?

Without actionscript all there is to a Flash project is animation. Actionscript is Flash's programming language, somewhat similar to javascript. If you think about it, any interactivity you will need requires some use of actionscript. Whether it be stopping a movie so it doesn't loop or adding script to inform users a movie is loading, actionscript is essential in most Flash projects. Ultimately actionscript increases the functionality and interactivity of projects. By learning actionscript you will have greater control over movie clips and the potential for creating fast loading dynamic projects increases.

According to Macromedia here are just a few things you can accomplish once you've gained actionscript knowledge:

For beginner's actionscript can be a new frustrating experience that often becomes a hurdle to fully grasping Flash. Remember, it is much like learning a foreign language. Much like it's easy to feel out of place in a country where you don't know the native language, actionscript can be tough to learn. According to Macromedia's article on "Actionscript 2.0's Best Practices" they found that: "Typically, you spend 80% of your development time debugging, troubleshooting, and practicing general maintenance, especially on larger projects. Even when you work on small projects, you'll spend a significant amount of time analyzing and fixing code." Yes, I know this is very reassuring, take this knowledge to allocate enough time for Flash projects - which as you'll come to find doesn't involve just development but also LOTS of testing.

Getting Started with Actionscript

In Flash there are three main ways we can apply actionscript to our movies:

There are three main ways to access the actions panel:

Your actionscript can be applied to two different sections in Flash:

Using Behaviors

Behaviors are available for many of the most common scripts you might use in Flash. They are super simple for beginner's to use. Always pay attention to whether you are applying actionscript to an object or a frame. If you apply the script to the incorrect location it won't function properly.

behaviors

Using the Actions Panel

To start familarizing yourself with actionscript we might want to make sure you can navigate your way around the actions panel. So let's take a look at a few points to note about the actions panel that will help make your first experiences a bit easier.

actions2

actions

Important points & terminology to note about Actionscript

Let's take a bit of time to point out some important points that will help when we use actionscript.

Breaking down a script

As you're probably beginning to notice, actionscript is a really complex language to learn. It'll help if we take a closer look at a script you'll probably use often.

actions3

Do make sure you note all the syntax to include dots, parenthesis, curly braces, quote marks, and semi-colons. Neglect the syntax and you'll quickly get frustrated with actionscript. Actionscript rewards those that are great at proofreading!

Understanding Timelines

So what makes Flash complex is not just actionscript - it's mastering all those timelines you'll be using! Remember, we can target movie clips or buttons if we give them an instance name - this can quickly become confusing if we don't get a better understanding of timelines. So let's take a look at how Flash refers to timelines:

timelines

Troubleshooting your scripts

It's impossible to develop a Flash project without errors. Errors are often typos, case sensitivity related, or forgetting to give your movie clips instance names. What's great is that Flash will alert you if it notices any syntax errors. Let's take a closer look:

output panel

So what do you do when your script goes wrong (because it will at some point)? Patience is certainly the best medicine for debugging Flash movies. Here are a list of some common errors for beginners:

When troubleshooting it's easy to get frustrated. Make your best attempt to solve problems but even the best developers will advise you that sometimes the best solution is to take a break and walk away from the script and come back to it.