Lingo 3 Tutorial: Events and Handlers READING: We are about to get into a little deeper waters now. You have to read carefully Chapter 8 of the D8D and answer all the questions within this tutorial
Objects have properties (can remember facts) and methods (can do things). During
the run of a program, Director is watching for "events".
Director's events are similar to JavaScripts events,
but they are many more than them. There are at least 27
such
events,
probably more than you can
learn
how to
use
effectively
in this
course.
We will
point out the ones that we view as really necessary. startMovie,
stopMovie, mouseDown,
mouseUp (rightMouseDown, rightMouseUp) idle Not
for now: activateWindow, deactivateWindow, openWindow,
closeWindow Sprite -> Cast -> Frame -> Movie -> Director For each of the above objects you can write event handlers to respond to the event. Once a handler is executed, the event stops propagating, unless the handler contains the pass command. A pass command will allow the propagation of the event up the hierarchy. PLAYBACK VISITS FRAME AFTER FRAME To
start this tutorial look at the file "playbackHeadEvents.dir". Make
sure the "loop playback" button is off (->|) Q1: Who sends the messages? Turn
on the "loop playback" button. What do
you expect to happen? Test it. MESSAGE HIERARCHY Now
run the movie "userActionsEvents00.dir",
and click on the red dot. You get the message Q3: Why? Now edit the sprite and frame scripts to Pass the messages
after you process them. Q4: Why? Edit the script of the cast member to pass the message.
What is the behavior of the clicks now? MOUSEDOWN Run
the movie "userActionsEvents01.dir", and click
on the red dot. Now you capture messages about mouseDown
instead of mouseUp. Yet
again, open the movie "userActionsEvents02.dir",
and bring your cursor over the red dot. Notice the reporting
of the script for
mouseWithin. Q5: Why there is no reporting mouse DOWN on the sprite?
Sprite
-> Cast -> Frame -> Movie -> Director Sing it 56 times every morning until you memorize it completely! MOUSEUPOUTSIDE AND THE locH SPRITE PROPERTY Open
the movie "userActionsEvents03.dir",
and bring your cursor over the red
dot. Notice the behaviour of the
script for mouseWithin now makes you chase the ball.
Try to click on the dot and release slowly.
Hear the beep.
Observe the behavior of the script
for mouseUpOutside. Q6: Why the mouseUpOutside is not activated
when you just click outside the dot? Q7: What other properties you can you guess exist for a sprite? How can you find out? MOUSEENTER, MOUSELEAVE AND THE visible PROPERTYOpen the movie "userActionsEvents04.dir", and bring your cursor over the red dot. When you move the cursor over the red dot, the text "WOW" to appear on the dot, and when you move the cursor away from the red dot, the text disappears. (Many programs' UIs have such a popup window these days, to explain what will happen if you click a button.) Q8: How do you do that?Guess and verify your answer by looking at the script. BOUNCE UP AND DOWNOpen
the movie "userActionsEvents05.dir",
run it, and try to guess what the scripts look like.
Verify that
your guess was right or find out why it was not. Q10: Modify the movie so that the ball bounces up and down, never sinking to the bottom for good. Explain how to do that. TIME ACTIVATED EVENTS There
are also two movies "timeEvents01.dir" and "timeEvents02.dir" that
wake up the user after 5 seconds with two different
ways: an alert box and going to another frame. Q11: Describe a situation in which the first way
is useful and another in which the second way is
useful. WHERE TO PUT THAT SCRIPT? So, you have figured out that you need to write a script, and what type of script it should be (sprite, cast member's frame's or movie's). But where do you find the actual location that will contain your script? Here is some help:
|
||||||||||||||||
Maintained By: Takis Metaxas
|