Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.
Find a file
2014-10-23 22:45:45 +03:00
libs Update local dependencies (Starling) 2014-07-23 16:43:31 +03:00
src/org/gestouch Add some logging 2014-10-23 22:45:45 +03:00
.gitignore Add Maven build support 2013-11-08 01:26:33 +02:00
build.template.properties Add ant property libs.dir to template 2013-01-06 18:16:35 +02:00
build.xml Update Ant build file for debug build 2014-10-23 22:45:32 +03:00
LICENSE Initial commit 2011-04-29 18:55:49 +03:00
pom.xml Update POM for debug build 2014-10-23 22:45:09 +03:00
README.md Update README 2014-07-24 17:46:29 +03:00
version.properties Sync Ant and Maven project version 2014-07-23 16:27:23 +03:00

Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.

Gestouch is a ActionScript (AS3) library that helps you to deal with single- and multitouch gestures for building better NUI (Natural User Interface).

Why? There's already gesture support in Flash/AIR!

Yes, last versions of Flash Player and AIR runtimes have built-in touch and multitouch support, but the gestures support is very poor: only small set of gestures are supported, they depend on OS, they are not customizable in any way, only one can be processed at the same time and, finally, you are forced to use either raw TouchEvents, or gestures (@see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/Multitouch.html#inputMode). Upd: With "native way" you also won't get anything out of Stage3D and of custom input like TUIO protocol.

What Gestouch does in short?

Well basically there's 3 distinctive tasks to solve:

  1. To provide various input. It can be native MouseEvents, TouchEvents or more complex things like custom input via TUIO protocol for your hand-made installation. So what we get here is Touches (touch points).
  2. To recognize gesture analyzing touches. Each type of Gesture has it's own inner algorithms that ...
  3. To manage gestures conflicts. As multiple gestures may be recognized simultaneously, we need to be able to control whether it's allowed or some of them should not be recognized (fail).

Gestouch solves these 3 tasks. I was hardly inspired by Apple team, how they solved this (quite recently to my big surprise! I thought they had it right from the beginning) in they Cocoa-touch UIKit framework. Gestouch is very similar in many ways. But I wouldn't call it "direct port" because 1) the whole architecture was implemented based just on conference videos and user documentation 2) flash platform is a different platform with own specialization, needs, etc. So I want Gestouch to go far beyond that.

Features:

  • Pretty neat architecture! Very similar to Apple's UIGestureRecognizers (Cocoa-Touch UIKit)
  • Works with any display list hierarchy structures: native DisplayList (pure AS3/Flex/your UI framework), Starling or ND2D (Stage3D) and 3D libs...
  • Doesn't require any additional software (may use runtime's build-in touch support)
  • Works across all platforms (where Flash Player or AIR run of course) in exactly same way
  • Extendable. You can write your own application-specific gestures
  • Open-source and free

Getting Started

All gestures dispatch (if you listen to!) GestureEvent with the next types: GestureEvent.GESTURE_STATE_CHANGE GestureEvent.GESTURE_IDLE GestureEvent.GESTURE_POSSIBLE GestureEvent.GESTURE_FAILED

Discrete gestures also dispatch: GestureEvent.GESTURE_RECOGNIZED

Continuous gestures also dispatch: GestureEvent.GESTURE_BEGAN GestureEvent.GESTURE_CHANGED GestureEvent.GESTURE_ENDED

If you use a good IDE (such as IntelliJ IDEA, FDT, FlashDevelop, Flash Builder) you should see these events in autocompletion.

Quick start:

var doubleTap:TapGesture = new TapGesture(myButton);
doubleTap.numTapsRequired = 2;
doubleTap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onDoubleTap);
...
private function onDoubleTap(event:GestureEvent):void
{
	// handle double tap!
}

or

var freeTransform:TransformGesture = new TransformGesture(myImage);
freeTransform.addEventListener(GestureEvent.GESTURE_BEGAN, onFreeTransform);
freeTransform.addEventListener(GestureEvent.GESTURE_CHANGED, onFreeTransform);
...
private function onFreeTransform(event:GestureEvent):void
{
	// move, rotate, scale — all at once for better performance!
	trace(freeTransform.offsetX, freeTransform.offsetY, freeTransform.rotation, freeTransform.scale);
}
  • Check the Gestouch Examples project for a quick jump-in
  • +Highly recommended+ to watch videos from Apple WWDC conferences as they explain all the concepts and show more or less real-life examples. @see links below
  • TODO: wiki?

Memory Management

To make Gesture object available for Garbage Collector:

  1. Important! Set gesture target to null or call dispose() method.
  2. Remove all other references you've created (e.g. event listeners).

@see examples for more details.

Advanced usage: Starling, ...

It is possible to work with Starling display objects as well as any other display list hierarchical structures, e.g. other Stage3D frameworks that have display objects hierarchy like Genome2D or ND2D or even 3D libraries.

In order to use Gestouch with Starling all you need to do is a bit of bootstrapping:

starling = new Starling(MyStarlingRootClass, stage);
/* setup & start your Starling instance here */

// Gestouch initialization step 1 of 3:
// Initialize native (default) input adapter. Needed for non-DisplayList usage.
if (!Gestouch.inputAdapter)
{
    Gestouch.inputAdapter = new NativeInputAdapter(stage);
}

// Gestouch initialization step 2 of 3:
// Register instance of StarlingDisplayListAdapter to be used for objects of type starling.display.DisplayObject.
// What it does: helps to build hierarchy (chain of parents) for any Starling display object and
// acts as a adapter for gesture target to provide strong-typed access to methods like globalToLocal() and contains().
Gestouch.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());

// Gestouch initialization step 3 of 3:
// Initialize and register StarlingTouchHitTester.
// What it does: finds appropriate target for the new touches (uses Starling Stage#hitTest() method)
// What does "-1" mean: priority for this hit-tester. Since Stage3D layer sits behind native DisplayList
// we give it lower priority in the sense of interactivity.
Gestouch.addTouchHitTester(new StarlingTouchHitTester(starling), -1);
// NB! Use Gestouch#removeTouchHitTester() method if you manage multiple Starling instances during
// your application lifetime.

Now you can register gestures as usual:

var tap:TapGesture = new TapGesture(starlingSprite);

Roadmap, TODOs

  • "Massive gestures" & Clusters. For bigger form-factor multitouch usage, when gestures must be a bit less about separate fingers but rather touch clusters (massive multitouch)
  • -Simulator (for testing multitouch gestures without special devices)- With new architecture it must be relatively easy to create SimulatorInputAdapter
  • Chained gestures concept? To transfer touches from one gesture to another. Example: press/hold for circular menu, then drag it around.
  • 3-fingers (3D) gestures (two fingers still, one moving)

News

  • "Follow me on Twitter for latest updates
  • Don't forget about github issues section as a good platform for discussions.

Contribution, Donations

Contribute, share. Found it useful, nothing to add? Hire me for some project.

License

See LICENSE file.