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

Watching Events

In this task, you'll take an initial look at some of the common events for which Director generates messages. A good way to do this is to set up handlers to catch particular messages and display them on the screen as they occur. A handler is a group of Lingo instructions designed to handle a particular message. (For a detailed discussion of handlers, see "Handlers and Handler Hierarchy" later in this lesson.)

1.
Open Start.dir in the Lesson 17 folder and save it as Events.dir in your Projects folder.

Start.dir contains the basic framework for detecting events.

2.
Choose Window > Score (Windows Ctrl+4, Macintosh Command+4) to open the Score window.

Only one sprite, Status, appears in the score. This sprite (cast member 2) is a text field on the stage.


Figure .


3.
Close the Score window (Windows Ctrl+4, Macintosh Command+4).

Now look at the cast.

4.
Choose Window > Cast (Windows Ctrl+3, Macintosh Command+3) to open the Cast window.


Figure .


Two cast members are visible. Cast member 2, Status, is a text type cast member. You use text cast members when you want to display formatted text on the stage. The text can be content that you have already entered in the cast member, or you can use Lingo to enter text in the cast member as the movie plays, as you will do in this lesson.

Cast member 1 is a movie script that contains the following Lingo script:

on setStatus newStatus
  member ("status").text = newStatus
end

on prepareMovie
  setStatus("PrepareMovie")
end

on startMovie
  setStatus("StartMovie")
end

on prepareFrame
  setStatus("PrepareFrame")
end

on enterFrame
  setStatus("EnterFrame")
end

on exitFrame
  setStatus("ExitFrame")
end

on stepFrame
  setStatus("StepFrame")
end

on stopMovie
  setStatus("StopMovie")
end

on mouseDown
  setStatus("MouseDown")
end

on mouseUp
  setStatus("MouseUp")
end

on keyDown
  setStatus("KeyDown")
end

on keyUp
  setStatus("KeyUp")
end


					  

This script consists of a dozen handlers, each beginning with the keyword on and ending with the keyword end. The script essentially has two parts. The first part is the first handler, setStatus.

on setStatus newStatus
  member ("status").text = newStatus
end

The setStatus handler takes a parameter, newStatus, and updates the contents of the text field, "status" (cast member 2). A parameter is an additional piece of information that can be passed to a handler. In this case, the handler takes the information, stored locally in a variable called newStatus, and uses it to update the text property of the Status cast member. You will use variables extensively in later lessons, but for now, you can consider a variable to be like a container that you can put things into for storage—like a cup or a box. Using Lingo, you can create variables and place values (names and numbers, for example) into them. You can also use Lingo to retrieve the values (or change the values) of variables as needed.

Most Director elements have various attributes that are specific to that type. These attributes are called properties. An 8-bit bitmap cast member, for instance, has a palette property that denotes what palette is assigned to the bitmap. A sprite has location properties that are determined by the sprite's location on the stage. In this case, the Status cast member is a text type, and text cast members have a property called text, which means that the text content is a string of characters. You can set this content through Lingo, which gives you the power to change the information stored in the text cast member.

Note

For a list of other properties of text cast members, choose Help > Lingo Dictionary. In the Help window that appears, click the Text selection under the Lingo By Feature heading. In the new display, you can scroll down to the Character Formatting Properties heading to find properties such as font and fontSize. Under the Text Cast Member Properties heading, you can find properties such as autoTab and kerning. Clicking any of the properties takes you to information about that property, where, among other things, you will learn whether you can set the property to a new value or simply view the existing value.

The second part of the script contains handlers that all perform a similar function: They catch, or handle, different messages and call on the setStatus handler to describe the messages they are handling. Look at two of these handlers:

on prepareMovie
  setStatus("PrepareMovie")
end

on startMovie
  setStatus("StartMovie")
end

These two instructions are similar except for the handler names and the text that gets placed in the Status cast member. You can see that when the prepareMovie handler is called, it sets the Status text to "PrepareMovie", and when the startMovie handler is called, it sets the Status text to "StartMovie". In other words, the setStatus function updates the Status field every time one of these handlers is invoked. As the movie runs, you can watch the Status field as it changes to report the last executed event.

5.
In the Score window, double-click frame 1 of the tempo channel. Use the slider to set the tempo to 1 frame per second (fps) and then click OK.

This slower tempo will allow you to see the changes in the Status field without their overwriting themselves too quickly to be read.


Figure .


6.
Bring the stage to the front by choosing Window > Stage (Windows Ctrl+1, Macintosh Command+1) and then click Play on the control panel or choose Control > Play (Windows Ctrl+Alt+P, Macintosh Command+Alt+P).

The movie plays, and you see the Status field updating in response to each of the messages received by the handlers in the movie script. Even at this slow tempo, many messages are being displayed too quickly for you to read them.

7.
Try generating messages of your own: Press the mouse button, release the mouse button, or type on the keyboard.

Your actions generate mouseDown, mouseUp, keyDown, and keyUp events that cause Director to send their respective messages.

8.
Stop the movie by clicking the Stop button on the control panel or choosing Control > Stop (Windows Ctrl+Alt+. [period], Macintosh Command+Alt+. [period]).

The playback stops, and "StopMovie" should appear in the Status field.

The stopMovie event is the last event that Director generates; you can use it to exercise some control over the movie at the time of its completion. For example, you can use this event to perform various cleanup tasks, such as saving any information entered by the user.

The Status field undoubtedly updated too quickly for you to see each event as it happened. What you really need is a printed log of events. Your next task will be to log the events to the Message window.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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