Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

Getting a Handle on ActionScript

  • Print
  • + Share This
This sample chapter will teach you how to use ActionScript to create effective Flash interaction by giving you the sound ActionScripting foundation upon which you can build your Flash literacy.
This chapter is from the book

ActionScript is Flash's scripting language for adding interactivity to your graphics and movies. You can use ActionScript to create anything from simple navigation within your Flash movie to complex interfaces that react to the location of the viewer's pointer, arcade-style games, and even full-blown e-commerce sites with dynamically updating data. In this chapter, you'll learn how to construct ActionScript to create effective Flash interaction. Think of the process as learning the grammar of a foreign language: First, you must learn how to put nouns and verbs together, and integrate adjectives and prepositions; then you can expand your communication skills and have meaningful conversations by building your vocabulary. This chapter will give you the sound ActionScripting foundation upon which you can build your Flash literacy.

If you are familiar with JavaScript, you'll notice some similarities between it and ActionScript. In fact, ActionScript is based on JavaScript, which is a popular object-oriented programming language for adding interactivity to a Web page. Whereas JavaScript is intended to control the Web browser, ActionScript controls the interactivity within Flash content, so the two scripting languages have slight differences. But the basic syntax of scripts and the handling of objects—reusable pieces of code—remain the same.

Even if you've never used JavaScript, you'll see in this chapter that Flash makes basic scripting easy. You'll learn about the logic of objects and how the Actions panel can automate much of the scripting process while giving you the flexibility to build more sophisticated interaction as your skills improve.

About Objects and Classes

At the heart of ActionScript are objects and classes. Objects are data types—such as sound, graphics, text, and numeric values—that you create in Flash and use to control the movie. A date object, for example, retrieves information about the time and the date, and an array object manipulates data stored in a particular order.

All the objects you use and create belong to a larger collective group known as a class. Flash provides certain classes for you to use in your movie. These predefined classes are also referred to as objects, but they are named and capitalized. The Color object, for example, is a class from which different color objects are created.

Learning to code in ActionScript centers on understanding the capabilities of these objects and their classes, and using them to interact with one another and with the viewer.

In the real world, we are familiar with objects such as a cow, a tree, and a person (Figure 3.1). Flash objects range from visible things, such as a movie clip of a spinning ball, to more abstract concepts, such as the date, pieces of data, or the handling of keyboard inputs. Whether concrete or abstract, however, Flash objects are versatile because after you create them, you can reuse them in different contexts.

Figure 3.1Figure 3.1 Objects in the real world include things like a cow, a tree, and a person.

Before you can use objects, you need to be able to identify them, and you do so by name just as we do in the real world. Say you have three people in front of you: Adam, Betty, and Zeke. All three are objects that can be distinguished by name. All three belong to the collective group known as humans. You could also say that Adam, Betty, and Zeke are all instances of the human class (Figure 3.2). In ActionScript, instances and objects are synonymous, and the terms are used interchangeably in this book.

Figure 3.2Figure 3.2 Adam, Betty, and Zeke are three objects of the human class. Flash doesn't have such a class, but this analogy is useful for understanding objects.

  • + Share This
  • 🔖 Save To Your Account