Primary Event Handlers -
This page looks at the use of Primary Event Handlers to create
scripts that could be used in a screensaver type application. There are
4 primary event handlers - keydownScript, mouseDownScript,
Lingo instructions (or messages) are executed following a hierarchical system. Primary event handlers are at the top of the message hierarchy and so will always be executed first (assuming they have been defined). Lingo or handlers are set to primary event handlers and will be executed whenever the event occurs. Primary event handlers will always pass down the event message unless you use the dontPassEvent command.
A user presses the mouse button generating a mouseDown event. Director will immediately look for a primary event handler relating to this event (i.e. mouseDownScript). If the primary event handler has been defined, it will be executed first. If a mouseDown sprite behavior exists, it will be executed next (or first if the mouseDownScript does not exist).
The order of the message hierarchy is:
primary event handler -> sprite behavior -> cast member script -> frame script - > movie script
In our screensaver movie we only need one movie script to check if a key has been pressed, the mouse has moved or the mouse button has been pressed.
gMouseLoc = the mouseLoc
-- records the initial location of the mouse
the keyDownScript = "CheckForKey"
-- when any key is pressed,
-- handler CheckForKey will be activated
the mouseDownScript = "if the mouseDown then halt"
-- when the mouse is pressed, Director will halt
-- on idle handler
will execute when no other handler
-- is being called
if the mouseLoc <> gMouseLoc then halt
-- if the mouse is moved from its starting position,
-- Director will halt
In the startMovie handler we record the initial mouse location
and we define 2 primary event handlers. For the keyDownScript
primary event handler, we assign a custom handler, and for the mouseDownScript,
we assign a single statement.
We could have replaced the line:
the keyDownScript = "CheckForKey"
the keyDownScript = "halt"
The CheckForKey handler is used to illustrate a custom handler can be assigned to a primary event handler. This would usually be done if there were a number of instructions relating to this event.
On Windows, the easiest way to convert a projector with the above script to a screensaver is to rename the exe file to a screensaverName.scr. However, when the screensaver is launched, it may be executed multiple times (as many as your memory can store). There are a number of programs that convert Director projectors to screensavers. AnySaver is free for Windows that activates the exe file rather than convert the projector itself. Other screensaver utilities can be found here.
If we want to create a screensaver-type movie that will exist within a
larger application, we will need to create a timeout in all our 'content'
movies. We can use the Timeout event (the only user variable event) as follows:
the timeoutLength = 10*60*60
-- set the timeout to 10 minutes
-- time is measured in ticks, 60 ticks = 1 second
the timeoutScript = "screensaver"
-- go to handler screensaver when the timeout occurs
-- go to screensaver
if the lastEvent > 10*60*60 then go to movie \
-- lastEvent function returns the amount of time
-- passed since the last user event occurred
-- user events are either a mouse click, mouse
-- movement or key press
If we then use the movie script at the top of this page in our screensaver movie, we could replace the halt command (when the screensaver ends) to a go to movie "main" statement, where main is the movie we go back to after the screensaver is deactivated.