ActionScript Mouse Gesture Library

Posted on the March 6th, 2010 under AS 3.0 by Vipin

A very easy to use Mouse Gesture class for AS 3.0 projects. The gesture is based on the mouse movements as shown below:

Mouse Gestures

Then you go on defining your gestures as a progression of these numbers. On to code:

Instantiate it. Pass the stage reference, or wherever you want it to work.

mg  = new MouseGesture(this.stage);

Add a gesture. Param 1: A string constant as an identifier. Param 2: The gesture number itself (above numbers) Here it is just a single action which will be ‘click and drag to right’ (see image)

mg.addGesture(PLAY,"0"); 

Add a complex gesture as a progression of above numbers. (Guess what it is)

mg.addGesture(STEP_BACKWARD,"65432"); 

Now add the listener.

mg.addEventListener(GestureEvent.GESTURE_MATCH,matchHandler);  

Now your listener.

private function matchHandler(event:GestureEvent):void

{

switch(event.datas)

{

case PLAY:

// DO whatever you want

break;

case GESTURE_MATCH:

// DO whatever you want. Yes again...

break;

}

}

Bingo! Easy, isn’t it?

Home Page

Download

Samples:

At ByteArray.org

Leave a Reply




XHTML::
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>