
As it turns out, I was able to get a pretty nice prototype in only 150 lines of code!
Click the image to try it out!
The Concept
When the user clicks the mouse down, tracks the mouse movement to an array. When the user releases the mouse, stop the recorder and match it's array values to a unique identity, a letter of the Alphabet.
Psuedocode
//global vars
var startX:Number = 0;
var startY:Number = 0;
var coordsArray:Array = new Array();
//add event listeners
addEventListener(MouseEvent.MOUSE_DOWN, start_record);
addEventListener(MouseEvent.MOUSE_UP, convert_record);
function start_record(e:MouseEvent):void{
startX = mouseX;
startY = mouseY;
addEventListener(Event.ENTER_FRAME, record);
}
function record(e:Event):void{
if(mouseX > startX){
//I moved the mouse Right
coordsArray.push("R");
}
else if(mouseX < style="color: rgb(153, 153, 153);">
//I moved the mouse Left
coordsArray.push("L");
}
}
function convert_record(e:MouseEvent):void{
removeEventListener(Event.ENTER_FRAME, record);
//now convert array values to Alphabet letter
switch(coordsArray.toString()){
case "U,R,D":
//the letter is A
break;
case "D,U,R,D,L":
//the letter is B
break;
case "L,D,R":
//the letter is C
break;
}
}
var startX:Number = 0;
var startY:Number = 0;
var coordsArray:Array = new Array();
//add event listeners
addEventListener(MouseEvent.MOUSE_DOWN, start_record);
addEventListener(MouseEvent.MOUSE_UP, convert_record);
function start_record(e:MouseEvent):void{
startX = mouseX;
startY = mouseY;
addEventListener(Event.ENTER_FRAME, record);
}
function record(e:Event):void{
if(mouseX > startX){
//I moved the mouse Right
coordsArray.push("R");
}
else if(mouseX < style="color: rgb(153, 153, 153);">
//I moved the mouse Left
coordsArray.push("L");
}
}
function convert_record(e:MouseEvent):void{
removeEventListener(Event.ENTER_FRAME, record);
//now convert array values to Alphabet letter
switch(coordsArray.toString()){
case "U,R,D":
//the letter is A
break;
case "D,U,R,D,L":
//the letter is B
break;
case "L,D,R":
//the letter is C
break;
}
}
There were a few tweaks I had to make to enhance the performance, but you get the idea. It works pretty well! Success!
0 comments:
Post a Comment