Skip to content

Instantly share code, notes, and snippets.

Created April 13, 2014 15:40
Show Gist options
  • Save anonymous/10589151 to your computer and use it in GitHub Desktop.
Save anonymous/10589151 to your computer and use it in GitHub Desktop.
import flash.events.KeyboardEvent;
this.stage.addEventListener(KeyboardEvent.KEY_DOWN , onKeyDown) ;
var pastKeyTime : int = -1 ;
var range : int = 2000 ;
var comboCount : int = 0 ;
var queryList : Array = [97,98,99,100,101,102] ;
var queryIndex : int = 0 ;
function onKeyDown(ev : KeyboardEvent = null) : void
{
trace(ev.keyCode) ;
//if( isTimeOut( getTimer() ) )
if(isQueryOut(ev.keyCode) )
{
comboCount = 0 ;
trace("reset") ;
}
else
{
comboCount ++ ;
trace("combo : " + comboCount) ;
}
}
function isQueryOut(code : int) : Boolean
{
var result : Boolean = code == queryList[queryIndex] ? false : true ;
trace(result + " " + code + " , " + queryList[queryIndex]) ;
queryIndex ++ ;
if(queryIndex > queryList.length -1 || result)
{
queryIndex = 0 ;
}
return result ;
}
function isTimeOut(nowTime : int) : Boolean
{
var result : Boolean = nowTime - pastKeyTime > range ? true : false ;
pastKeyTime = nowTime ;
return result ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment