What Scripts Are

I l @ ve RuBoard

ActionScript is a programming language. A programming language is a list of instructions that tell a computer what to do. A computer will obey these instructions exactly as they are stated.

Little Programs Inside Flash

graphics/newterm.gif

A list of instructions for the computer is called a program. Another name for a program is a script. From now on, I'll refer to these lists of instructions as scripts.

A program or script exists inside an environment. In the case of ActionScript, that environment is the Flash movie. A script can tell the Flash movie what to do. In some cases, a script can tell other things, such as the user 's Web browser or computer's operating system, what to do. But for the most part, scripts can control only what's inside the Flash movie.

Scripts can be as small as one line, or as long as thousands of lines. They can be placed in one central part of the Flash movie or sprinkled throughout the Flash movie. Some people will refer to an entire Flash movie that uses scripts as a program, whereas other people will refer to each individual script in the movie as a program. Both definitions are technically true because a single program can be defined as many smaller programs. It is just a matter of semantics.

For the most part, scripts are little programs placed on various frames and elements inside Flash movies. Later in this hour , we'll examine exactly where in the Flash movie these programs can be placed.

graphics/cup.gif

You may already be familiar with some programming languages. JavaScript is the language understood by most Web browsers and is commonly used to make Web pages interactive. Internet Explorer understands JavaScript and a similar language called VBScript. HTML (Hypertext Markup Language) is an unusual programming language that you might be familiar with. It issues a series of instructions to the Web browser about how to display text and images.

If you have used Macromedia Director before, you may have written some programs with Lingo, its programming language. Even though Director and Flash have many similarities, Lingo and ActionScript are very different languages.

In high school or college, you may have taken a course in programming. Many people are taught BASIC (Beginners All-Purpose Instruction Code), Pascal, or even COBOL.

With the exception of HTML, all the languages mentioned use similar constructs: loops , conditions, variables , and so on. You'll be able to apply these skills to ActionScript as soon as you know the specific syntax that ActionScript uses. However, if you have never learned a programming language before, don't worry. I'll show you everything you need to know in the upcoming hours.


Origins of ActionScript

So where does ActionScript come from? It actually has its roots in many different places. Let's take a moment to learn about where computer languages came from.

When digital computers were first created, the only way to program them was in their native language: binary code. This is simply a list of 1's and 0's. When different groups of 1's and 0's are combined and fed into a computer, it can trigger the computer to behave in different ways. A long program written this way might perform a simple task such as adding two numbers together.

Instead of rewriting binary code every time someone wanted to add two numbers together, this code was written in such a way that it could add together any two numbers. Instead of writing the code over again, you could simply reuse the code, but feed it different numbers each time. Little functions like this were soon created to handle all sorts of tasks such as addition, subtraction, multiplication, comparisons, looping, and so on. Pretty soon, instead of writing in binary code, you could use these prewritten functions to perform almost any task.

Today's modern computer languages are much easier to understand and use than binary code and its immediate successors. For one thing, modern computer languages look like English. Words such as "go," "for," "begin," and "if" are used, as well as operators such as +, -, and =.

Some computer languages, such as BASIC, Pascal, and Macromedia Director's Lingo, can almost be read like English sentences. They are easy to learn and understand. Other languages, such as C and Fortran, look very technical. They are more powerful in the hands of experienced programmers. More recent languages form a balance between these two sides. Languages such as C++, Java, and JavaScript are readable, yet powerful. ActionScript is similar to these recent languages.

graphics/book.gif

Flash follows the standard created by the ECMA (European Computer Manufacturers Association). ActionScript is actually similar to ECMAScript, a language developed by that organization. JavaScript also attempts to follow this standard. So rather than ActionScript being based on JavaScript, as many people think, both ActionScript and JavaScript are based on a common ancestor .


Flash always had some capability for interactivity. The earliest versions could use navigation controls and buttons with some simple scripted instructions. But basically, Flash was a vector-based animation tool. It caught on like wildfire because of the needs of Web site designers. They needed a tool to be able to create graphically intense , but low bandwidth sites. Because vector shapes are defined by lines, curves, and fills rather than pixels, they make much smaller files than do bitmap images. Thus, Flash allowed designers to create nice Web pages without leaving out the people using slow modems.

Even though Flash was meant primarily for illustration and animation, there was a need for some scripting. For instance, designers wanted buttons that allow the user to navigate to another Web page.

graphics/book.gif

When Flash first appeared, it was actually called FutureSplash. Later on, it was bought by Macromedia, renamed , and added to Macromedia's product line.


Scripting in early versions of Flash was simple. It wasn't until Flash 4 that standard programming structures, such as conditional statements and loops, were added. But Flash scripting was still done with pull-down menus and fill-in-the-blank forms. It could barely be considered a programming language.

Real ActionScript was born with Flash 5. Programmers could type their programs directly and attach them to the elements of the Flash movie. Flash MX expands ActionScript even further. ActionScript now provides more than 300 commands, functions, operators, and constructs. It is truly a full-featured programming language.

What Scripts Look Like

Scripts are basically English words with mathematical symbols and punctuation. Here is an example:

 on (press) {     gotoAndPlay ("my frame"); } 

You can decipher what this code does by examining the key words in it. The word "press" suggests that the user is clicking on something, in this case a button. The long word on the next line can be read "go to and play" and suggests that the script is commanding Flash to go to a specific point in the movie and play the movie from that point on.

This script demonstrates that ActionScript can control the flow of a Flash movie. We'll look at the script shown previously in more detail later on. Before we go further, let's examine what other powers ActionScript can have over the Flash movie.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net