• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Introducing Interactivity > More modifications with Lingo

More modifications with Lingo

So far, all our scripts have been concerned with the playback head in one way or another. Either we've been pacing its progress or shuttling it about. But scripts can also be written that pay no heed to where the playback head is, instead affecting the general condition of the movie—in fact, we can write scripts that make changes not only to the movie but to Director itself. And that's exactly what we'll tackle next, with a few more sophisticated buttons that offer yet another level of interactivity.

Turning off sound with a toggling button

Let the movie run, and this time keep your mouse off the Avoid button. After a while, the sound of a voice going "Ouch" repeatedly may get a wee bit annoying. Wouldn't it be nice to build in the option of making our character a little more stoic?

We can do this by creating a button that affects the volume of the soundtrack. One approach would be to include two buttons, Sound On and Sound Off; but a more elegant solution is a single toggling button, one that turns the sound off when it's on, and on when it's off. This requires some new Lingo and a new button, but both are easy enough to create.

  1. Click frame 1, channel 5, of the Score.

  2. Using the Tool Palette, create a new push button in the upper-left corner of the Stage. Label it Sound.

  3. Extend the Sound button sprite through to the end of the movie.

  4. With the entire Sound button sprite selected, click the Behavior Inspector button to open the Behavior Inspector.

  5. Select New Behavior from the Behavior pop-up menu and name the new behavior Sound Control.

  6. Choose Mouse Up as the event.

Now we need to add another arrow to our programming quiver. We want to turn sound on (or off), but the Behavior Inspector doesn't have a built-in action for that. We need to add some custom Lingo to do the job.

  1. Instead of using the Action button, click the Script button of the Behavior Inspector.

Lingo away:

Click the Script button of the Behavior Inspector to open the Script window and add your own Lingo script.

Figure .

The script editor opens with the beginning and ending of a mouseUp event handler, the event we specified. Now we need to add the Lingo that is to be executed when the mouseUp event occurs on our Sound sprite.

  1. After the line on mouseUp me, type this line:

    set the soundEnabled to not (the soundEnabled)

Be sure to keep the text on a single line (you may have to scroll in the Script window) and include the parentheses and the unusual midCapitalization.

  1. Close the Script window.

Let's take a look at that line of script. What we're doing here is actually turning off Director's ability to produce sound. We're not just suppressing the "Ouch" sound effect or turning down its volume; we're making the entire application temporarily mute. The condition of Director's sound is known in Lingo as the soundEnabled. When the soundEnabled is turned off (or set to FALSE), Director is hushed. When the soundEnabled is turned on (or set to TRUE), the program returns to its normal noise-ready state.

In this case, we've turned the soundEnabled neither on nor off. The set…to not construction means simply to change the condition to the opposite of what it currently is. Thus, the result of the button will change after each push, first turning the sound off and then on (the first click will turn off the sound because the default state of the soundEnabled is TRUE, or on).

Play your movie and try out the new button. You should be able to toggle the sound off and on.


Although we told you to place the previous Lingo command on a single line, you didn't actually have to. If you need to include a long command that you want to place on two lines, you can use the continuation symbol ( \ ) to break up the line and tell Director to read the command as if it were a single line. You create the \ character by pressing Alt-Enter (Windows) or Option-Return (Macintosh). So the last command we wrote could be written just as well as

								set the soundEnabled to }
								not (the soundEnabled)

We will use this continuation symbol throughout the book when we need to break long lines so they fit on a page. When you see it, you can enter the lines as shown or combine them onto a single line.

We also told you to maintain the same funny midWord capitalization, as in soundEnabled. Actually, in general Director doesn't pay attention to capitalization, so you could write soundenabled, SOUNDenabled or even SoUnDeNaBlEd. Look at the last example and you'll realize why the single mid-word capitol letter is best. Not only is it the most readable, it's also the way you'll find Lingo written in the documentation. The times when Director does pay attention to capitalization have to do with matching a word exactly—we'll point it out when we need it.

Displaying sound status

There's just one hitch, right? Since the button is called Sound, after a few clicks it's easy to lose track of the sound status, and then the only way to tell if the sound is on or off is by waiting to hear (or not hear) the "Ouch." What's needed is a display on the Stage to indicate the sound status.

This is a good opportunity to demonstrate that the script of one Cast member can be used to affect another Cast member. We'll place a text sprite on the Stage and then add some Lingo to our Sound button that will actually change the contents of that sprite.

  1. From the Window menu, select Text to open the Text window.

  2. Set the formatting by clicking the Bold button and the Align Center button.

  3. Type the words Sound On in the text area.

  4. Click the Cast Member Name field in the top center of the Text window. Type Sound Status.

Sound off (or on):

Use the text field to enter text that will be displayed in the Sound Status field on the Stage.

Figure .

  1. Close the Text window.

Look at the new Cast member's slot in the Cast window. You should have a Cast member named Sound Status in slot 20 containing the words "Sound On."

  1. Click frame 1, channel 6, of the Score. Then drag the new Cast member from the Cast to the Stage. Position it to the right of the Sound button. Adjust the sprite's size so it approximates the size of the text.

  2. In the Score, use Extend Sprite to extend the sprite from frames 1 to 50.

If you played your movie now, this text display would have only a 50 percent chance of being accurate at any given moment. We chose Sound On because that's the default state of Director, but now we need to change that text whenever the soundEnabled changes. We'll do that by changing the script for the Sound Control behavior:

  1. In the Cast window, select the Sound Control behavior and then click the Script button on the Cast window's toolbar.

  2. Press Return before the end line to open a new line.

  3. Type the following:

    if the soundEnabled = TRUE then
        member ("Sound Status").text = "Sound On"
        member ("Sound Status").text = "Sound Off"
    end if

Place a regular Return character (press Enter [Windows] or Return [Macintosh]) at the end of each line. As you do so, you'll see that Director automatically indents the added lines to different points. The end result should be similar to the illustration shown here. If it isn't, don't try to insert the indentation yourself; clear what you've just typed and start again.


The if/then/else statement is a basic tool for telling Director which way to go at a crossroad in the movie.

Figure .

What we have here is a basic if/then/else statement: if a certain state of affairs exists (the soundEnabled = TRUE), then do something (change the text of) to some entity (Cast member Sound Status). Otherwise (else), do something else. Note that this if statement requires its own ending (end if) before the end of the script as a whole.

The Lingo we've added uses a syntax known as dot syntax. This is a feature that debuted with Director 7; it's a scripting dialect closer to the programming syntax used with other programming languages. In earlier editions of this book, same script segment would have looked like this:


Director uses dot syntax, which is a scripting dialect closer to the programming syntax used in other programming languages.

if the soundEnabled = TRUE then
    set the text of member "Sound Status" to "Sound On"
    set the text of member "Sound Status" to "Sound Off"
end if

Both scripting styles will work in Director 8, although from here on in this book, we'll focus on the dot syntax. Why? Because the handwriting is on the wall for the old-style syntax: Don't count on Director's supporting it forever.

In the Director help files and documentation, you'll find Lingo elements listed in both forms. If you already know Lingo from an earlier version of Director, feel free to use the old style—for now, at least. But if you're learning Lingo from scratch, I recommend using the dot syntax; you'll be able to translate some key concepts more readily into other languages like Java and Perl.

Now play your movie. If it works as expected, the Sound Status text should be accurate 100 percent of the time, since it changes with each click of the Sound button.

Creating a Quit button

We have one last button to add before we turn this movie into a freestanding projector. Unless we want to induce frustration, we need to give the end user some means of exiting the program (remember that in the final product, Director's Quit menu choice won't be available).

  1. Create and place a button titled Quit on the Stage, below the Play button.

  2. In the Score, extend the button's sprite to the length of the movie.

  3. Use the Behavior Inspector to create a new behavior and name it Quit.

  4. Choose Mouse Up as the behavior's event.

  5. For the action, select Exit from the Navigation behaviors.

If you look at the script for the behavior that we just created, you will see that the Lingo command used is halt. This command causes a projector to quit. When you are authoring in Director, though, it simply stops the movie, just as if you had clicked the Stop button on the Control Panel. Director also has a quit command that not only quits a projector but quits Director as well. You'll find the halt command to be much less frustrating.

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