on keyDown
179
// JavaScript syntax
function isOKToAttach(aSpriteType, aSpriteNum) {
switch (aSpriteType) {
case symbol("graphic"): // any graphic sprite type
return sprite(aSpriteNum).member.type != symbol("shape");
// works for everything but shape cast members
case symbol("script"): // the frame script channel
return false; // doesn't work as a frame script
}
}
on keyDown
Usage
-- Lingo syntax
on keyDown
statement(s)
end
// JavaScript syntax
function keyDown() {
statement(s);
}
Description
System message and event handler; contains statements that run when a key is pressed.
When a key is pressed, Director searches these locations, in order, for an
on keyDown
handler:
primary event handler, editable field sprite script, field cast member script, frame script, and
movie script. For sprites and cast members,
on keyDown
handlers work only for editable text and
field members. A
keyDown
event on a different type of cast member, such as a bitmap, has no
effect. (If pressing a key should have the same response throughout the movie, set
keyDownScript
.)
Director stops searching when it reaches the first location that has an
on keyDown
handler,
unless the handler includes the
pass
command to explicitly pass the
keyDown
message on to the
next location.
The
on keyDown
event handler is a good place to put Lingo that implements keyboard shortcuts
or other interface features that you want to occur when the user presses keys.
When the movie plays back as an applet, an
on keyDown
handler always traps key presses, even if
the handler is empty. If the user is typing in an editable field, an
on keyDown
handler attached to
the field must include the
pass
command for the key to appear in the field.
Where you place an
on keyDown
handler can affect when it runs.
•
To apply the handler to a specific editable field sprite, put the handler in a sprite script.
•
To apply the handler to an editable field cast member in general, put the handler in a cast
member script.
•
To apply the handler to an entire frame, put the handler in a frame script.
•
To apply the handler throughout the entire movie, put the handler in a movie script.
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...