Skip to content

Instantly share code, notes, and snippets.

@trxcllnt
Created March 26, 2010 03:04
Show Gist options
  • Save trxcllnt/344437 to your computer and use it in GitHub Desktop.
Save trxcllnt/344437 to your computer and use it in GitHub Desktop.
package org.tiny.tlf.interaction.gestures
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import org.tiny.tlf.events.GestureEvent;
public class GestureBase implements IGesture
{
public function GestureBase()
{
}
protected var state:XML = <_/>;
protected var currentState:XML;
protected var behaviors:Vector.<IEventDispatcher> = new Vector.<IEventDispatcher>();
public function addBehavior(behavior:IEventDispatcher):void
{
if(behaviors.indexOf(behavior) < 0)
behaviors.push(behavior);
}
public function execute(event:Event):void
{
currentState = currentState.children().length() > 0 ? currentState[0] : state;
var funcName:String = currentState.localName().toString();
if(funcName in this)
{
var result:Boolean = (this[funcName] as Function).apply(this, event);
if(result)
{
if(currentState.children().length() == 0)
notifyBehaviors(event);
}
else
currentState = state;
}
}
protected function notifyBehaviors(event:Event):void
{
var n:int = behaviors.length;
for(var i:int = 0; i < n; i++)
behaviors[i].dispatchEvent(new GestureEvent(GestureEvent.ACTIVATED, event));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment