Writing Lingo Scripts for Macromedia Director MX
In This Chapter
- What Is Lingo?
- Creating Scripts
- Understanding Lingo Elements
- Navigation with Lingo
- Understanding Messages and Behaviors
- Writing Lingo Code
- Did You Know?
What Is Lingo?
Lingo is the programming language used in Director movies. Unless you stick to bare bones, PowerPoint-like presentations or linear animations, you need to learn Lingo to use Director to its full capabilities.
Lingo code is stored in cast members called scripts. There are three different types of script members: movie scripts, behavior scripts, and parent scripts. In addition, other cast members, such as bitmaps, can have scripts embedded inside them. These are usually referred to as cast scripts.
The difference between script types is not in what they look like or how they behave, but in when they act. Here is a summary:
Movie scriptContains handlers that can be accessed by any other script. Cannot be assigned to specific sprites or frames.
Behavior scriptAssigned to sprites or frames. Controls the sprite or frame that it is assigned to.
Parent scriptCan be used only by object-oriented programming techniques.
Cast scriptExists inside a cast member. Only affects that one cast member, but affects every sprite instance of the cast member.
A movie script is a global presence in a movie. If a movie script produces a system beep whenever the mouse is clicked, this script sounds the beep whenever the mouse is clicked anywhere in the movie. Thus the name movie script: It acts on the entire movie.
A behavior script does nothing until it is placed on a sprite or in a frame script channel. When a behavior script is placed on a sprite, the Lingo commands inside the script are active only as far as the sprite is concerned. If you have a behavior that plays a beep when the mouse is clicked, for example, and you apply that behavior to a sprite, the beep sounds only when users click that sprite. Behavior scripts are sometimes called sprite or Score scripts for this reason. They act only on a sprite in the Score to which they are assigned.
For more information about behaviors, see "Creating Simple Behaviors," p. 319.
Behavior scripts can also be assigned to the frame script channel of the Score. When they are, they act like movie scripts, but only for the frame or frames to which they are assigned. Behaviors used this way are sometimes called frame scripts.
Parent scripts are a different type of script. They actually don't do anything until you use some object-oriented programming Lingo commands to tell them how and when they are to be used.
You would use parent scripts if you like object-oriented programming. This means that the code and the data exist in special objects that can be duplicated and modified.
For more information about parent scripts, see "Using Parent Scripts," p. 345.
Cast scripts, on the other hand, are easy to use. You can create one by selecting a member, such as a bitmap, and clicking the Script button at the top of the Cast panel. This opens the Script panel and enables you to add a script to that particular member.
Cast scripts act only on that one cast member. If you place a script with a cast member that makes the system beep when users click the mouse, that action affects only that one cast member when it is on the Stage. If you use that cast member more than once in the Score, the script that is a part of that cast member is active in all those places.
Cast scripts are not used much with modern Lingo programming. Behaviors can accomplish the same tasks and are much more flexible. However, they do come in useful when you want to create some quick buttons without crowding a Cast with both the button members and the scripts that are assigned to them.