User Guide
Checking keys with Lingo or JavaScript syntax 297
• To set up script that runs when the mouse pointer is within a sprite’s bounding rectangle when
the playhead enters the frame that contains the sprite, place the script in an
on mouseWithin
event handler.
The
mouseWithin event can occur repeatedly as long as the mouse pointer remains
inside the sprite.
• To determine whether the cursor is over a specific sprite, use the rollOver() method.
Finding mouse pointer locations with Lingo or JavaScript syntax
Determining where the mouse pointer is on the Stage is a common need in Director.
To determine the mouse pointer’s horizontal and vertical positions:
• Use the mouseH and mouseV properties. For more information about these properties, see the
Scripting Reference topics in the Director Help Panel.
The
mouseV property returns the distance, in pixels, between the mouse pointer and the upper-
left corner of the Stage. The
mouseH property returns the distance, in pixels, between the mouse
pointer and the upper left corner of the Stage.
The statements
put the mouseH and put the mouseV display the mouse pointer’s location in
the Message window.
For example, this handler directs the Message window to display the distance (in pixels) between
the pointer and the upper left corner of the Stage:
on exitFrame
put(_mouse.mouseH)
put(_mouse.mouseV)
_movie.go(_movie.frame)
end
Checking keys with Lingo or JavaScript syntax
Lingo or JavaScript syntax can detect the last key that the user pressed. For more information, see
the Scripting Reference topics in the Director Help Panel.
• To obtain the ANSI value of the last key that was pressed, use the key property.
• To obtain the keyboard’s numerical (or ASCII) value for the last key pressed, use the keyCode
property.
A common place for using
key and keyCode is in an on keyDown handler, which instructs the
script to check the value of
key only when a key is actually pressed. For example, the following
handler in a frame script sends the playhead to the next marker whenever the user presses Enter
(Windows) or Return (Macintosh):
on keyDown
if the key = RETURN then go to marker (1)
end