• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Getting rolling

To start, let's give the Rolling.dir movie the most basic of interactive controls: Let's give the user the ability to start the action.

Now you may well ask, "Isn't that what the Control Panel is for?" True, the Control Panel gives us that ability, but it's part of the Director application. Bear in mind that a movie can be converted into an application in its own right, which is called a projector. A projector doesn't need to invoke Director to operate—and thus the Control Panel (and every other Director window, for that matter) is absent. If you want to put controls in your projector, you need to put them directly on the Stage of your movie.


A Director movie that stands alone as its own application.

  1. Open your Rolling.dir movie (or the one suppl ied on the CD).

  2. On the File menu, choose Save As to make a new copy of the movie. Name it Rbuttons.dir.

Before we can begin to build our buttons, we need to make one more slight modification to the movie. When we create our projector, we'll want the action on the Stage to wait until the user clicks a Play button, so we need to instruct the Score to pause on the very first frame. We already know how to do that: We'll add a behavior.

  1. On the Library Palette, find the Navigation behaviors and drag the Hold on Current Frame behavior to frame 1 of the behavior channel.

Now when the movie plays, the playback head stays in frame 1, and the movie does not proceed. Notice that the film loop of Swifty is playing fine, although Swifty isn't getting anywhere. If you don't want him to be moving, you can replace the film loop in the first frame with one of the graphics of Swifty.

Adding a script to the Score

That's right—it's time to get your hands on Lingo. You'll find that, at least on the level of basic interactivity, Lingo is a lot like plain English. To get an idea of what a Lingo script looks like, let's look at the behavior we just created.

  1. Double-click the behavior in the first cell of the behavior channel.

A Behavior Script window opens, displaying the Lingo script that makes up the behavior. Right now, we are concerned with only three lines. However, in the upper lines, you should recognize the description of the behavior that appears in the Behavior Inspector and, below that, the description that appears as a Tooltip on the Library Palette.

The three lines we are interested in are in the middle and begin with the line on exitFrame me. Those three lines do all of the work of keeping the playback head in one location. Just in case you don't believe it, we're going to get rid of this behavior and then add it again with a script we write ourselves.

  1. Close the Behavior Script window and then delete the behavior from the behavior channel.

  2. Find the behavior in the Cast window (it should be Cast member 12 and named Hold on Current Frame) and delete it, too.

  3. Double-click (the now empty) frame 1 of the behavior channel.

Double-clicking a blank cell in the behavior channel opens the Script Editor window so you can enter Lingo code. Some of the Lingo is provided for you by default (though you could change it). Remember that three thing are happening here: We're creating a Lingo script, we're creating a new Cast member (Cast member 12), and we're placing that Cast member in the selected channel within the selected frame.

The cursor is positioned in between the two existing lines of Lingo, right where you want it.


When carrying out Lingo instructions in this book, type only the words shown in this typeface.

  1. Type go to the frame

You've just completed your first Lingo script! The three lines that now appear in the window are almost identical to the three lines we saw in the behavior. Let's look at the script's anatomy.

A few words:

Many Lingo commands are simple, straight-forward English words such as go or end.

Figure .

The line on exitFrame me is what's known as an event handler. It tells Director that it needs to do something when a specific event occurs. In this case, the event occurs when the playback head leaves this frame (hence, exitFrame).


A unit of Lingo code intended to be executed in correlation with a particular event.

The line you wrote is a command. Director recognizes the phrase go to the frame as meaning "the frame you are going to next is this same frame"; the frame is a Director function that returns the frame number of the current frame (in our case, 1). So go to the frame is equivalent to "go to frame 1."

That may seem convoluted (why not just stay in one place?), but keeping the playback head in motion means that more than one thing can be happening on the Stage, even in one frame.

The final line is the Lingo equivalent of a period. It contains the word end to tell Director that we're through giving orders for now. Since this line is needed to complete the script unit started by on exitFrame, it's also considered part of the event handler. Think of the words on and end as the bookends of every event handler.

Notice how the middle line is indented. Lingo (and other programming languages) use such indentation to show that multiple lines form a single unit. You can look at a script as a sort of sandwich, with the command in the middle between layers of "when" and "that's all." Notice also that the words are color coded: Words in blue, green, and black have special meaning to Director. When you write more complicated scripts, you will be using your own words, and they should appear colored gray. Actually, you can set the exact colors used through the Script Preferences (on the File menu).

  1. Close the Behavior Script window; then rewind and play the movie.

It works, right? Even though the Play button remains depressed on the Control Panel, the playback head in the Score stays on frame 1. That's Lingo in action. We created a behavior that acts just like the behavior we got from the Library Palette.

Don't be fooled here. Just because we created our behavior with three lines of Lingo (and had to write only one) doesn't mean that all Library Palette behaviors are so simple. Some of the behaviors require hundreds of lines of Lingo. Then again, once you have a good understanding of Lingo, you won't think twice about writing hundreds of lines of Lingo yourself.

Building the Play button

Now that we've written and placed a Lingo script that stops our movie in its tracks, we need to have to add a behavior that overrides the first script.

We have to make a home for this behavior before we write it, since it doesn't belong in the behavior channel.

  1. Click frame 1, channel 4, of the Score. That's where our button will reside.

  2. Open the Tool Palette and use the Button tool to draw a button box in the lower-left corner of the Stage.

  3. Type the word Play in the button.

  4. Use the handles on the selection border to resize the box to suit your taste.

The button behavior

We could write this behavior using the script editor, but it's time to reintroduce the Behavior Inspector as a tool for creating behaviors rather than just inspecting them.

  1. With the Play button still selected in the Score, click the Behavior Inspector button in the Score window or on the toolbar.

  2. Click the Behavior button (the plus sign) and then select New Behavior.

Behave yourself:

You can create behaviors as well as inspect them from the Behavior Inspector.

Figure .

A big event:

Events specify when something will occur, such as a mouse click or a key press; this behavior responds to the mouseUp event.

  1. In the Name Behavior dialog box, name the behavior Start and click OK.

  2. Click the Events button and choose Mouse Up.

A wealth of event choices appear. The standard for buttons is for an action to take place when the mouse button is released, so choose Mouse Up.

  1. Click the Action button and select Navigation and then Go to Frame.

Take action:

Actions specify what will take place when an event occurs; in this case, the movie will jump to a frame when the Start button is clicked.

Figure .

  1. In the Specify Frame dialog box, enter 2; then click OK.

Now we have created a behavior that is attached to the button and responds to a mouse click. When the button is released (the event), the playback head goes to frame 2 (the action). Jumping to frame 2 will get us beyond the control of the frame behavior that's keeping us in frame 1.

Notice that the event handler for the behavior we just created responds to the release of the mouse button. The event (actually mouseUp) is the last half of a mouse click, when the mouse button returns to its original position (mouseDown, the first half, is considered a separate event). Director knows to execute this behavior when the user finishes a mouse click, and since the behavior belongs to a sprite (the Play button), Director runs the script only when the mouse is clicked on that sprite.

That's all we need to make the button work, so you can close the Behavior Inspector. The Play button is in frame 1 only, which is just fine; it wouldn't make sense for it to appear throughout the movie, since it provides no functionality elsewhere.

Now play the movie. The playback head will remain in frame 1 (and so will the action) until you click the Play button.

Looping with a frame behavior

Just as we duplicated the Control Panel's Play function with a custom button, we will build the equivalent of the Looping feature into our movie, but because we'll leave looping permanently turned on, we won't need to create a button for it. Instead, we'll go to the very end of the Score and add a script that sends the playback head sailing back to the beginning of the action. Since such a behavior is particular to a specific frame, it's called a frame behavior. First, we need to add a marker to go to.

  1. Place a marker at frame 2 in the marker channel. Name it Replay.

  2. Click a cell in the Score that does not contain a sprite; then click the Behavior Inspector button.

The Behavior Inspector opens. Now we'll create a new behavior. If a sprite is selected in the Score when you create this new behavior, the new behavior will automatically be attached to the sprite—not what we want. Instead, we want to place the new behavior in the behavior channel.

  1. Click the Behavior button and select New Behavior. Name the new behavior Loop and then click OK.

  2. Click the Events button and then select Exit Frame.

This is the same event that we used to loop on frame 1 of the movie to hold the movie in one place. Now we'll use it to loop back to replay the movie.

  1. Click the Action button and select Navigation and then select Go to Marker.

  2. In the Specify Marker dialog box, choose Replay. Then close the Behavior Inspector.

Meet your marker:

Select a marker from this menu to tell the playback head where to jump.

Figure .

The Specify Marker pop-up menu lists the current markers in the movie as well as three relative jumps. Selecting a marker makes the playback head jump to that marker. Selecting one of the relative jumps moves the playback head to a marker determined by the marker's proximity to the current frame. If you chose Next in the pop-up menu, for example, the playback head would move to the first marker following the current frame.

Why loop back to frame 2 and not frame 1? Because we built a pause into frame 1, returning there wouldn't have the effect of looping, since the movie would simply pause at frame 1.

  1. Drag the Loop behavior from the Cast window to the behavior channel at the last frame of the movie.


Keep in mind that "the last frame" means the last frame presently occupied by a sprite in your production, not the last available cell in the Score (that's a long way to travel).

Now run the movie with looping turned off in the Control Panel. You should have continuous action.

Adding a nonlinear leap button

I don't know about you, but I can watch our little man get painfully frontswiped only so many times. Let's use nonlinear navigation to introduce another fate. We can add another button that makes the playback head leap past the moment of collision, avoiding the unpleasantness.

First we need to add a marker to jump to. It's difficult to add a marker so near to another existing marker, so we'll do things a little differently this time:

  1. Click frame 27 in the playback head area. Then, from the Insert menu, choose Marker. Name this marker 8 Ball Gone.

This is the first frame after the collision and the ball's subsequent dissolve, where the stroll resumes. This time, instead of using the Tool Palette to create our button, we'll use a shortcut approach built into Director.

  1. Select frame 2, channel 4, in the Score window.

  2. From the Insert menu, choose Control; then choose Push Button.

Control freak, eh?

The Insert menu provides an alternative method of adding various types of buttons to your productions.

Figure .

A familiar button appears at the center of the Stage and occupies the highlighted frame in your movie.

  1. Give the button the title Avoid 8 Ball.

  2. Drag the new button to the lower-left area of the Stage.

  3. Using the Extend Sprite command, extend this button through frame 24.

Frame 25 is the point of collision, so after frame 24 the button is super fluous.

  1. With the sprite segment still selected, click the Behavior Inspector button.

  2. Click the Behavior button and select New Behavior. Name the new behavior Avoid.

  3. For the event, choose Mouse Up.

  4. For the action, choose Navigation and then Go to Marker.

  5. In the Specify Marker dialog box, choose 8 Ball Gone; then click OK. Close the Behavior Inspector.

You could also use a behavior to specify the frame number, as we did earlier, but citing the name of a marker allows you a little more flexibility. You can move the marker or add and subtract frames, and the script will still be valid.

Now run the movie and try out your handiwork. If you click the Avoid 8 Ball button in time, the playback skips the collision and goes right to frame 26. On the Stage, it seems as if Swifty just keeps walking, albeit with a bit of a lurch.

Since the looping from our frame script is in effect, you can forestall as many 8 Ball assaults as you like. See how close to the collision you can get before clicking the button. In effect, what you've created is a basic video game of the reflex-testing variety.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint