Getting a Handle on ActionScript
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.
About Objects and Classes
At the heart of ActionScript are objects and classes. Objects are data typessuch as sound, graphics, text, and numeric valuesthat 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.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.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.