please continue developing as you please and ask any questions,
common uses:
check if expression was typed
cheats
other nifty similar stuff
instructions:
first of all create a new instance of the class by typing
my_keyqueue=new KeyQueue(<your max length here>);
//the longer the max is the bigger cheats it can contain and the more usage it takes
my_keyqueue.listen();//starts key queuing
//actual checking for cheats
this.onEnterFrame=function(){/*if in movieclip put anything before this in a onClipEvent(load) and everything from now on in an enter frame*/
if(my_keyqueue.cheatCheck("hey lolz"){//replace hey lolz with your cheat
//actions that trigger when cheat is true go here
}
you can use this for a lot more than cheats
this is a pretty simple docs I just whipper up:
NOTE: inherits from the MovieClip class to enable pathing (passing this to the listener)
properties:
innerQueue :Array;
this is the actual queue the data goes in and out of. this is encapsulated so apart from knowing it's there it's not really an interest
constructor:
KeyQueue(length:Number)
creates a new KeyQueue the length of the passed parameter
Functions:
function getLastKey(Void):Number - returns the last typed key, pretty useless but it makes sense to have it there, type my_keyqueue.getLastKey(); to get the last user typed key
function listen(Void):Void -starts the actual watching over the user keys, use this to activate the actual capture
function getKeyFromQueue(pos:Number):Number - returns the pos key typed, for example if you typed omg, getKeyFromQueue(17) would return 'o' I believe in a 20 sized queue,
function toString(Void):String - convers the current KeyQueue to a string, usage: trace(my_keyqueue.toString);
the qts function is irrelevant, it basically does what toString does but being private you can't access it
function wasTyped(expression:String):Boolean - checks if the last expression typed is equal to the passed string for example wasTyped("hello") returns a boolean true if the last typed thing was "hello"
public function cheatCheck(expression:String):Boolean -identical to wasTyped
enjoy the code :)
(simple code instructions: copy contents into a new file, call it KeyQueue.as , the name is IMPORTENT, any other name WILL CAUSE A FAULT, put it in the same directory as your .fla file, the output will still be one .swf file, don't worry)
This code is under the GNU GPL meaning, edit it freely, distribute it freely, gimme credit
dynamic class KeyQueue extends MovieClip {
//KeyQueue Class V.01 by Inglor September 15th 2005
private var innerQueue:Array;
function KeyQueue(leng:Number) {
innerQueue = new Array(leng);
for(i=0;i<leng;i++){
innerQueue[i]=65;
}
}
public function getLastKey(Void):Number {
return Key.getAscii();
}
public function listen(Void):Void {
_root.keylisten = new Object();
_root.keylisten.creator = this;
_root.keylisten.onKeyDown = function(Void):Number {
this.creator.innerQueue.push(Key.getAscii(
));
return this.creator.innerQueue.shift();
};
Key.addListener(_root.keylisten);
}
public function getKeyFromQueue(pos:Number):Number {
return this.innerQueue[pos];
}
public function toString(Void):String {
s = new String();
for (var i = 0; i<this.innerQueue.length; i++) {
s += String.fromCharCode(this.innerQueue[i]);
}
return s;
}
private function qts(a:Array):String {
s = new String();
for (var i = 0; i<a.length; i++) {
s += String.fromCharCode(a[i]);
}
return s;
}
public function wasTyped(expression:String):Boolean {
var loc:Number = this.innerQueue.length-expression.length;
s = this.qts(this.innerQueue).substr(loc,this.
innerQueue.length);
trace(s);
return (s == expression);
}
public function cheatCheck(expression:String):Boolean {
return this.wasTyped(expression1);
}
}