Event Handlers
Lingo is an event-driven programming language. Anything that happens, happens in response to an event. An
event handler
is a piece of code that responds to an event:
on event
do things ...
...
end
Mouse Events
Usually, put these into a Behavior Script and attach it to a particular sprite.
mouseEnter
the mouse has entered the sprite.
mouseLeave
the mouse has left the sprite
mouseDown
user has pressed the mouse button
mouseUp
user has released the mouse button
example
on mouseEnter
sprite(1).member = "button highlight"
end
on mouseLeave
sprite(1).member = "button"
end
on mouseDown
sprite(1).member = "button pushed"
end
on mouseUp
sprite(1).member = "button highlight"
end
Keyboard Events
keyDown
a key has been pressed
keyUp
a key has been released
Example
put this is a Behavior Frame script if you want it to be active for just one frame,
or in a movie script if you want it to be active throughout the whole movie.
on keyDown
put "Pressed" && the key && the keycode
end
on keyUp
put "Released" && the key && the keycode
end
Frame Events
exitFrame
the playback head has exited the frame. This event is used for several things:
- to make sections of score loop
- to hold the playback head on a single frame
- in animated Sprite Behaviors, to run continuous update scripts every frame
examples
-- frame script: loops back to frame 1
on exitFrame
go 1
end
-- frame script: loops to most recent marker
on exitFrame
go loop
end
-- frame script: hold on one frame
on exitFrame
go the frame
end
-- Sprite Behavior: continually move this sprite to random locations
on exitFrame me
sprite(me.spritenum).loch = random(500)
sprite(me.spritenum).locv = random(300)
end
Movie Events
These events are used in Movie Scripts, rather than in Behavior Scripts.
startMovie
runs once, when the movie begins. Used for initializing global variables, settings, loading data.
stopMovie
runs when the movie ends. Use this to do cleanup tasks; for instance, freeing up video input or serial port devices.
Example
global score
on startMovie
score = 0
end
on stopMovie
alert ("Goodbye - thanks for Playing!")
end