Back to Lesson 1
Forward to Lesson 3

Lesson 2 - The Playback Head and

the frame

You'll probably have noticed that when you run a movie in Director, the playback head (the vertical red line in the score) moves horizontally to the right 'reading' and displaying the sprites in each frame on the stage. This is fine for linear animations, although you can get much better results authoring linear animation with Adobe After Effects or Macromedia Flash. If you want to do something more flexible and interactive you are probably going to need to create a stable state where the playback head is not rushing off somewhere else all the time.

The first Lingo anyone should ever learn, therefore, is that which tells the playback head to loop continuously in the same frame. you can use a looping playback head to drive the interactivity like a motor.

There are other techniques that some people find useful which involve stopping the playback head altogether and creating your own tight loop, but this has now been officially discouraged by Macromedia so I'm not going to cover those here. Tight loops also have a tendency to dominate all the processor time. Too bad if you happen to be downloading a file in the background. Here's how to make a simple frame loop then:

Have a look in the score. On the left you will see a column of numbers, each referring to a sprite channel, the 'layers' of the visual part of your movie. At the top of them, above a little popup menu is another channel with a little icon of a script instead of a number. This is the framescript channel and it is where you will put scripts which will apply to particular frames. Double-click in the framescript channel in the score window and fill in the script as follows...

on exitFrame
  go to the frame
end

When you do this, you will create and attach a new score script (or behavior) cast member. The script cast member is therefore attached to the frame where you double-clicked. You can attach the same script to other frames by dragging the cast member into the framescript channel and you can delete the attachment by selecting it in the score and using the normal keyboard backspace / delete key.

If you delete an attached script from the score, the script cast member remains in the cast. Watch out, because if you delete the cast member, the framescript channel keeps a reference to the slot in the cast where the cast member used to be, which might cause complications later.

Whenever the playback head leaves a frame, Director takes care that an

exitframe

message is sent to all scripts attached in that frame.

on exitframe

means "when the exitframe message is received here, do the following things..."

go is a lingo instruction to the playback head to go to a particular frame. The to is optional, but it is essential that you specify which frame you want the playback head to go to.

the frame stands in for a whole number, which is always the current frame number. This is always exactly the same as the number you can see displayed in the control panel.

end means "I've finished describing what should happen when the message is received here".

You have just completed a handler. All handlers have the following skeletal structure:

on message
  instructions
end

...and there can be any number of instructions, though each one must occupy a line to itself. This script therefore instructs the playback head to go back to the same frame it is just leaving. This is perhaps the most fundamental Lingo script of all, so you really ought to get to know it by heart. It is rare to make a Director presentation which does not include a script like this.

Incidentally, because we want to loop in frame 1, we could just as well have written...

on exitFrame
  go to 1
end

...but then we would be obliged to keep this script and all the action in frame 1. If we later decided to make an animated introduction for the game in frames 1-20, we would have to modify and move the script. If we wanted to have loops in several different frames, we would be obliged to make several versions of the same script. By using

the frame

...it doesn't matter which frame we use, and we can reuse the same script.

This illustrates a general principle which will come up again and again. Basically it's smart to write your scripts once, and then refine them for reuse instead of writing hundreds of new and unique scripts which do essentially the same job. There are several very good reasons for this and I will return to the principle and highlight those reasons later in this tutorial.

the frame

is a lingo property, a term which will be described later. All you need to know for now is it refers to the particular frame the playback head is at. If you open the Director control panel, you will see

the frame

displayed there. Notice the way it changes as you click in different frames in the score.

If you run your movie you will notice that the playback head seems to stop where the script is. Try dragging the attached script to another frame, rewind and play the movie. Notice the way the playback head plays normally until it reaches the script. When you're happy with that, drag it back to frame 1.

Actually, the playback head does not stop at all, although it might seem like it. It keeps moving, but because it stays in the same frame it looks stationary. Those

exitframe

messages that are keeping it in one place are going to be very useful...

 

Forward to Lesson 3