Types of Lingo Scripts


A Lingo script is a series of one or more handlers. You can attach a script to any of the following elements of your Director movie:

  • A sprite

  • A frame

  • A cast member

  • The movie as a whole

A script attached to a sprite or frame is often referred to as a behavior script, or a Score script . A script attached to a cast member is a cast-member script. And a script attached to a movie is a movie script . (A more advanced type of script, called a parent script, is not covered in this book.) With the exception of cast-member scripts, every script appears as a cast member in the Cast window ( Figure 15.4 ).

Figure 15.4. The various kinds of script cast members as they appear in the Cast window.


The element to which a script is attached determines when and where the script is executed, as described below.

Behavior scripts

Behavior scripts are simply a different name for the behaviors you learned about in Chapter 14, "Adding Behaviors." As you saw in that chapter, you can create behaviors by using the Events and Actions pop-up menus in the Behavior Inspector ( Figure 15.5 ). You can achieve much more flexibility, however, by writing behaviors as Lingo scripts in a Script window ( Figure 15.6 ). In either case, once a behavior has been created, you use it by dragging it from the Cast window onto a sprite, or into a frame in the script channel of the Score.

Figure 15.5. The Behavior Inspector offers a menu-driven approach to creating behaviors.


Figure 15.6. Writing behavior scripts gives you much more control than using the Behavior Inspector.


You can attach multiple behavior scripts to one sprite, but you can attach only one script per frame in the script channel. If a sprite has multiple behaviors that respond to the same event, each of them is executed in the order in which you attached them. You can see which behaviors have been attached to a sprite ”and their order ”by selecting the sprite and opening the Behavior Inspector.

A behavior script attached to a sprite may be triggered by any of the following events:

  • Movement of the mouse pointer relative to the sprite (for example, on mouseEnter or on mouseLeave ).

  • Pressing or releasing of the mouse button when the mouse pointer is positioned on the sprite (for example, on mouseUp or on mouseDown ).

  • Pressing or releasing of a key on the keyboard (for example, on keyUp or on keyDown ).

  • The playhead's entering or leaving the sprite in the Score (for example, on beginSprite or on endSprite ).

A behavior script attached to a frame is generally triggered when the playhead prepares to enter, enters, or leaves the frame to which the script is attached (for example, on prepareFrame , on enterFrame , or on exitFrame ).

Cast-member scripts

A cast member may have only one script attached to it, and a cast-member script may be attached to only one cast member. If a cast member has a script attached to it, the presence of that script is indicated by an icon in the lower-left corner of the cast member's thumbnail in the Cast window ( Figure 15.7 ).

Figure 15.7. A cast member with an attached script.


A cast-member script works the same way as a behavior script attached to a sprite. It can respond to any of the same mouse or keyboard events that a behavior script responds to. (It can't respond to movement of the playhead, however.)

A cast-member script remains attached to any sprite that's created from that cast member. So, for example, suppose you create a visual cast member and attach the following script to it:

 on mouseDown    go to frame 1 end 

Any sprite based on that cast member will function as a button that returns the playhead to frame 1 when the user clicks it.

If you have a cast member that you want to use as a button, but you want the button to do different things at different points in the movie, don't attach a cast-member script to it. Instead, attach a behavior script to each sprite based on the cast member.

Movie scripts

A movie script is not explicitly attached to any object; instead, it's available to the entire movie. Two types of handlers are generally placed in movie scripts:

  • Handlers that are triggered by the playing or stopping of the movie (for example, on prepareMovie , on startMovie , or on stopMovie ).

  • Handlers that are meant to be executed at any time during the movie, regardless of what sprites are on the Stage or where the playhead is. For example, if you want the backspace key to be available to rewind the movie at all times, you might include the following handler in a movie script:

     on keyDown    if the key = BACKSPACE then go to frame 1 end 

    A movie may contain any number of movie scripts. If a movie contains two movie scripts that respond to the same event (meaning they both use the same handler), only the first one that Director finds is executed. The other movie script is ignored.


Macromedia Director MX for Windows and Macintosh. Visual QuickStart Guide
Macromedia Director MX for Windows and Macintosh. Visual QuickStart Guide
ISBN: 1847193439
Year: 2003
Pages: 139

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net