10
gesture

working with gestures

rollovers

often we want to react to a user moving the mouse pointer over a certain area, frequently as an acknowledgement that we received their input, and we understand where the pointer is.

in fact, this is such a common behavior for web applications that Flash devotes a whole symbol flavor to it—the button symbol. a Flash button symbol is basically a specialized movie clip that has some hardwired code that jumps the playback head to a specific frame when a rollover event occurs. it has only four frames, one for each of its three main events: mouse off, mouse over, mouse down, and one to define its hit area (hotspot).

so creating a simple button in Flash is very simple, and requires no code:
[.swf] [.fla]

following

create a new movie clip, put the following code on the first frame of its time line, and draw a simple shape in it:

stage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void { x = stage.mouseX; y = stage.mouseY; });

hiding

flash has a built-in Mouse object which provides the very handy method pair hide() and show(). these two methods give us control over displaying the operating system cursor over the flash movie or not.
[.swf] [.fla]

tracing

a custom cursor mimics the user's gestures, but what if we want to see more lasting evidence of recent gestures?

we could store the last known mouse coordinates, and at every frame draw a line from there to the new mouse coordinates, giving us a simple paint program.
[.swf] [.fla]

marking

but one issue becomes quickly obvious: what if we don't always want the ink turned on? we need to store some idea of our current state—either on, or off, and to be able to toggle between them.

the trigger for entering the on state will be the press of the mouse button, and the trigger to enter the off state will be the release of the mouse button. to be notified of the button events, we need to assign event handler functions to the root movie clip's onMouseUp and onMouseDown event properties. then, at every frame, we'll check to see if we're on; if so, we'll draw.
[.swf] [.fla]

 

further investigations