Scripting Navigation

   

One of the most common uses for Lingo scripts is for setting up a movie's navigation structure that is, a series of buttons or menus that permits them to view only the parts of the movie that they want to see, in the order that they want users to see them ( Figure 15.30 ). A navigation structure consists of two equally important aspects: a user -interface design (or front end ) that lets users know where there are and how to get to where they want to go; and a technical mechanism (or back end ) that makes the user interface work. Designing a good front end is too big a topic to be covered in this book (and is, in fact, the subject of many books in its own right), but this section will show you a few scripting techniques you can use to set up the back end.

Figure 15.30. The buttons in this movie, with their attached Lingo scripts, allow users to decide which parts of the movie they want to see.

graphics/15fig30.gif

The first two tasks in this section will show you how to make a movie pauseeither by making the playhead stop at a specific frame in the Score or by making the playhead loop continuously between two frames until the user provides input by clicking a button. The remaining tasks will show you how to attach a script to a button that will make the playhead jump to a different frame in the Score.

These techniques will work best with a movie that has been designed as a collection of separate scenes. Each scene should have its own place in the Score, perhaps separated from the others by a few empty frames ( Figure 15.31 ). For the greatest efficiency, label each scene with a marker (see "Setting Markers" in Chapter 3).

Figure 15.31. This Score is ideally set up for random access by users. Each scene occupies its own section of the Score and is identified by a marker.

graphics/15fig31.gif

How you set up the front end is up to you, but you'll probably want to have the playhead stop or loop at the end of each scene, until the user can choose which scene he or she wants to go to next .

To make the playhead pause at a frame:

  1. In the script channel of the Score, select the frame at which you want the playhead to pause ( Figure 15.32 ).

    Figure 15.32. In the script channel, select the frame where you want the movie to pause.

    graphics/15fig32.gif

  2. Double-click the selected frame.

    or

    Choose New Behavior from the Behaviors pop-up menu on the Sprite toolbar.

    A Script window opens, displaying the first and last lines of a handler.

  3. In the Script window, type go to the frame as the middle line of the handler ( Figure 15.33 ).

    Figure 15.33. This script causes a movie to pause by making the playhead play the same frame over and over.

    graphics/15fig33.gif

    The keyword the identifies the frame at which the playhead is located at the time Director executes the script. In other words, the frame means "the frame to which this script is attached."

  4. Close the Script window.

  5. Rewind and test the movie.

    When the playhead reaches the frame you selected in step 1, it goes no further.

graphics/tick.gif Tip

  • Unlike Macromedia's Flash ActionScript, Director has no "stop" command. The playhead in a Director movie never stops. Instead, this script creates a one-frame loop, in which the playhead plays the same frame over and over again.


To make the playhead loop between two frames:

  1. In the script channel of the Score, select the later of the two frames you want the playhead to loop between ( Figure 15.34 ).

    Figure 15.34. In the script channel of the Score, select the later of the two frames between which you want the playhead to loop. (In this example, we want the playhead to loop between frames 6 and 10, so frame 10 is selected.)

    graphics/15fig34.gif

  2. Double-click the selected frame.

    or

    Choose New Behavior from the Behaviors pop-up menu on the Sprite toolbar.

    A Script window opens, displaying the first and last lines of a handler.

  3. If you want the playhead to loop back to a specific frame, type go to frame X as the middle line of the handler, with X identifying the frame you want the playhead to loop back to.

    Note that X may be either a frame number or the name of a marker. If it's the name of a marker, it must be enclosed in quotation marks ( Figure 15.35 ). If it's a frame number, it must not be enclosed in quotation marks ( Figure 15.36 ).

    Figure 15.35. This script causes the playhead to loop back to the marker called "intro."

    graphics/15fig35.gif

    Figure 15.36. This script causes the playhead to loop back to frame 6.

    graphics/15fig36.gif

    or

    If you want the playhead to loop backward by a specific number of frames, type go to the frame - X as the middle line of the handler, with X being the number of frames. For example, if you want the playhead to loop back to the frame that's 4 frames before the current frame, you'd type go to the frame - 4 ( Figure 15.37 ).

    Figure 15.37. This script causes the playhead to loop back 4 frames.

    graphics/15fig37.gif

    or

    If you want the playhead to loop back to the closest previous marker, type go loop as the middle line of the handler ( Figure 15.38 ).

    Figure 15.38. This script causes the playhead to jump back to the closest previous marker.

    graphics/15fig38.gif

  4. Close the Script window.

  5. Rewind and test the movie.

    When the playhead reaches the frame you selected in step 1, it loops back to the frame you identified in step 3 and repeats that pattern indefinitely.

To script a button that makes the playhead jump to a new frame:

  1. Select a cast member (in the Cast window) or a sprite (on the Stage or in the Score) that you want to use as a button ( Figure 15.39 ).

    Figure 15.39. Select a cast member (as shown here) or a sprite that you want to use as a button.

    graphics/15fig39.gif

  2. If you selected a sprite, choose New Behavior from the Behaviors pop-up menu on the Sprite toolbar.

    or

    If you selected a cast member, click the Cast Member Script button in the Cast window.

    A Script window opens, displaying the first and last lines of a handler.

  3. If you want the playhead to jump to a specific frame, type go to frame X as the middle line of the handler, with X identifying the frame to which you want the playhead to jump.

    Note that X may be either a frame number or the name of a marker. If it's the name of a marker, it must be enclosed in quotation marks ( Figure 15.40 ). If it's a frame number, it must not be enclosed in quotation marks.

    Figure 15.40. This script causes the playhead to jump to the marker called "scene2."

    graphics/15fig40.gif

    or

    If you want the playhead to jump forward or backward by a specific number of frames, type either go to the frame + X or go to the frame - X as the middle line of the handler, with X being the number of frames. For example, if you want the playhead to jump to the frame that's three frames after the current frame, you'd type go to the frame + 3 ( Figure 15.41 ).

    Figure 15.41. This script causes the playhead to jump ahead three frames.

    graphics/15fig41.gif

    or

    If you want the playhead to jump forward or backward by a specific number of markers, type either go to marker ( X ) or go to marker (- X ) as the middle line of the handler, with X being the number of markers. For example, if you want the playhead to jump to the next marker, you'd type go to marker(1) ( Figure 15.42 ).

    Figure 15.42. This script causes the playhead to jump ahead to the next marker.

    graphics/15fig42.gif

  4. Close the Script window.

  5. If you attached the script to a cast member, make sure there's a sprite on the Stage based on that cast member.

  6. Rewind and test the movie.

    When you click the button to which you attached the script, the playhead jumps to the frame you identified in step 3.

To script a button that makes the playhead jump to a new frame, and then return:

  1. Follow the directions for the preceding task ("To script a button that makes the playhead jump to a new frame"), but in step 3 replace the phrase go to with the word play ( Figure 15.43 ).

    Figure 15.43. This script causes the playhead to jump to the marker called "scene3." The use of play rather than go to means that the playhead will be able to return to the frame it departed from.

    graphics/15fig43.gif

  2. Select the final frame of the scene to which you made the playhead jump in step 1 ( Figure 15.44 ).

    Figure 15.44. Select the final frame of the scene to which you made the playhead jump to (in this case, the final frame of Scene 3).

    graphics/15fig44.gif

  3. Double-click the selected frame.

    or

    Choose New Behavior from the Behaviors pop-up menu on the Sprite toolbar.

    A Script window opens, displaying the first and last lines of a handler.

  4. In the Script window, type play done as the middle line of the handler ( Figure 15.45 ).

    Figure 15.45. The play done command returns the playhead to the frame from which it departed.

    graphics/15fig45.gif

  5. Close the Script window.

  6. Rewind and test the movie.

    When you click the button to which you attached the script in step 1, the playhead jumps to the frame you specified in the script. When the playhead reaches the frame to which you attached the play done script in steps 3 and 4, it jumps back to the frame it was in when you clicked the button.

graphics/tick.gif Tip

  • The play command can also be used to play an entirely different movie. For an example, see "To create a stub projector with external movie files" in Chapter 16.


   


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

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