MACROMEDIA DIRECTOR AND LINGO

Cast
Score
Movie
Stage
Menus

Programming
Events
Handlers
Scripts
Debugging
Variables
Lists
Objects
Puppets

Shockwave


Cast

A cast is a database of multimedia objects. Everything that appears in your movie is refered to as a cast member. That includes all of the images, whether they are snapshots of a cartoon character in motion, props on the stage, or background images. Titles and labels are also cast members. So are the buttons you push and the text areas that you write in. Even the sound effects and instructions to the computer (scripts) are cast members.

All cast members are stored in a cast, which may be viewed with the cast window (select Cast from the Window option on the menu bar). A cast members may be referenced by a number (reflecting its position in the cast) or a name that you gave it. You can rearrange cast members within the cast at any time, so it's a good idea to always refer to cast members by their name rather than their number.

Although something must be a cast member in order to appear in the movie, cast members don't actually appear in the movie until they are placed on stage.


Score

The score tracks the action in your application. The score is similar in appearance (and function) to timing sheets used in traditional animation. The main part of the score is a large table divided into rows and columns. Each column corresponds to a different instant of time or frame. Each row corresponds to a different channel. The numbered channels are the sprite channels, which show what sprites are on the stage. Notice that there is a limit to the number of sprites that can appear on stage at any one time. There are also special channels for everything else that goes on in the movie, including two sound channels, a timing channel, and a script channel (for computer instructions).

When you play your movie, Director does this by showing one frame after another until it reaches the end of the movie. It starts at the current frame, so you have to rewind if you want to start from the beginning. The end of the movie is the last frame (column) that has anything in it. You can set the frame rate in either the control panel or in the timing channel.


Movie

The resulting application, described by the Score, is called a Movie. A movie has a beginning, a middle and an end. You can play the movie, stop the movie, rewind the movie. You can even splice movies together, or show a movie inside another movie.

When you save a movie, Director creates a file on your disk. This file contains all the necessary information about your movie, so you can always go back and change it. One of the nice things about Director is that the movie file format is platform independent. This means you can create a movie on a Macintosh and then play/edit that movie on a Windows computer, or vice versa (as long as you have Director installed on both machines).


Stage

All the action in your movie takes place on the stage. It's that big blank area that you see when you first start up Director. You create your movie by arranging your cast members on the stage. Placing cast members on the stage is very easy: you simply click on the cast member you want, and then drag it onto the stage (while holding down the mouse button; releasing the button "drops" the cast member where it is).

What you see on the stage is actually a copy of the cast member known as a sprite. Each sprite has properties such as its position on stage and its size (you can make it bigger or smaller). This means that if you have one picture of a bird in your cast, you can use that to create a hundred birds of various sizes all over the stage.


Menus


Programming Capabilities

Program Flow

Director handles events internally, then gives your application the opportunity to perform additional tasks in response to the event.


Event-Driven Program

A Lingo "program" is actually a collection of scripts or handlers. Playing a movie can be viewed as a succession of events. The movie starts; each frame is shown (entered and exited); the movie stops. Director also recognizes several other events: a mouse button is clicked; a key on the keyboard is pressed; a timer runs out. Normally, these events go by unnoticed. That is, unless the creator of the movie has written event handlers indicating that something else should be done.

An event handler is a sequence of instructions to the computer. When the named event occurs, the computer follows (executes) the instructions within the handler. Handlers are written in scripts using a language called Lingo. Lingo is a powerful scripting language that supports everything you would expect from a programming language: branching and conditional statements; local and global variables; sequential and associative arrays; string, numeric, and boolean operators. It even supports a form of object-oriented class definition. Lingo is what makes Director a powerful tool for creating interactive multimedia. It's also a fun language to learn and use, whether you're an experienced programmer or a complete novice.

A handler is invoked in response to either an event or a direct call. Director automatically captures and delivers the following events:

Event Hierarchy

Director uses a hierarchy to determine what handler (if any) should respond to a given event:

Overriding the Event Hierarchy

You may also intercept this hierarchy by defining a primary event handler:

Example:

set the keyDownScript to "detectKeys"

After the specified handler is executed, it passes the event on to the usual event hierarchy unless it encounters a dontPassEvent instruction.


Handlers

Handlers are subroutines (procedures or functions) that accomplish specific tasks.

Personal Handlers

Handlers are defined using the syntax:

on handlername [ param1, param2, ... ]
    statements
end [ handlername ]

In addition to performing tasks, a handler may return a valuereturn expressionHandlers are called one of two ways

Handlers and Events

A block of code, starting with "on" and ending with "end", is known as a handler.

Each handler corresponds to some event. When that event occurs, all of the statements in the corresponding handler are executed in sequential order. Events may be triggered by the user doing something (like clicking the mouse button) or they may occur naturally as part of playing the movie (like going from frame to frame). The programmer can also define events. It's important to remember that Director will always do precisely what it is told to do, in the order that it is told to do it in.

Playing a Movie

startMovie

stopMovie

enterFrame

exitFrame

Triggered by User

keyDown

mouseDown

mouseUp

idle



Different Types of Scripts

In addition to handling a lot of different kinds of events, Lingo allows you to relate an event to some object in the movie. So, for example, you could have a bunch of buttons on the stage, and something different happens when you click each one.

A script may be associated with a sprite, a cast member, a frame in the movie, or the entire movie. Whenever a pre-defined event occurs, Director takes the following steps:

Using the Script Window

Before writing a lot of Lingo scripts, it's good to become familiar with the script window.


It's important to note that Director doesn't necessarily know about your scripts until you do one of two things:

When you do this, Director will check for syntax errors (i.e. determine whether or not it knows how to follow the instructions you have given it). If there are syntax errors, a pop-up window will give you the choice of ignoring the errors (not a good idea) or going to the place in the script that is causing the error. It's then up to you to debug your program.


Debugging With the Message Window

As with all programming languages (and, in fact, all languages of any kind), Lingo has its own syntax and semantics. Semantics are concerned with the meaning of statements in the language. Syntax is concerned with rules of how these statements are structured.If the statements in your program don't follow the syntactic rules exactly, the computer won't know what to do, and so it will give up. The semantics are equally precise: the computer will only do exactly what it is told to do, in the order it is told to do it in.

Each Lingo statement appears on a separate line; when the line ends, the statement ends. Whenever a handler is invoked, Director interprets and executes the statements line by line. Director also provides a message window (select Window -> Message from the menu bar) where you can type in Lingo commands. When you press the Enter key, Director interprets and executes that statement. This is a good way to test Lingo statements (to see what they do). It's also a good way to check the values and types of variables.


Variables

Variables are named memory slots that contain information that may change as the program is executed

Variable Types

Variable type is determined by its contents. A variable that has not been assigned a value has a default value of <Void>.

Variable Assignment and Operators

Variable values are set one of two ways:

set varname to expression

set varname = expression


Lists

Lists are ordered sets of values, like arrays or records (struct) in other programming languages.

Linear Lists

Linear lists contain sequences of values, referred to by their positions.

Property Lists

Property lists contain labeled values, referred to by their labels. You may also use numbers instead of labels.


Objects

An object is an entity with properties and behaviors defined by a class.


Working with Puppets

Normally the Score determines what cast members appear where on the stage, keeping track of 48 sprite channels and their attributes in each frame. However, your Lingo scripts may also control the appearance of the stage by manipulating sprite attributes. In order for your script to take control of a sprite channel, you must make that sprite a puppet.

Changing Sprite Properties

To change the attributes (properties) of a sprite channel, use the following Lingo statement:set the property of sprite sprite_channel to valueYou may set the following properties of a sprite:

These changes will not appear on the stage until the stage is updated. You may do this by You may set sprite properties (including the puppet property) in the following Lingo scripts:

Guidelines for Creating Shockwave Movies

Make your movie as small as possible, to reduce download times

Observe the limitations on Lingo top of page