Created
March 26, 2010 03:04
-
-
Save trxcllnt/344437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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