/* CLASE CHEATCODES Hernan Rivas Acosta hernanrivasacosta@gmail.com 2007 Esta clase permite crear de forma muy práctica distintos trucos. */ class hernan.CheatCode { // private static var listener:Object; private static var cadenaActual:String; private static var trucos, funciones:Array; private static var cantTrucos, maxCars, largo, i:Number; // private static var tepmArr, teclasPresionadas, arrayConfirmacion:Array; // Usamos esta función para crear una instancia public static function nuevo (truco:String, func:Function, rut:MovieClip):Void { // if (trucos == undefined) { // Creamos los 5 Arrays que necesitamos trucos = new Array (); tepmArr = new Array (); funciones = new Array (); arrayConfirmacion = new Array (); teclasPresionadas = new Array (); maxCars = 0; // iniciarListener (); } // if (truco && func) { // Separamos el truco en letras tepmArr = truco.split (""); // Actualizamos el largo máximo de los trucos largo = tepmArr.length; if (largo > maxCars) { maxCars = largo; } // Agregamos el truco a los 2 Arrays trucos.push (tepmArr); funciones.push (func); cantTrucos = trucos.length; } } // Con esta función eliminamos un truco public static function eliminar (truco:String):Void { // Buscamos el truco y o eliminamos for (i = 0; i < cantTrucos; i++) { if (trucos[i].join ("") == truco) { trucos.splice (i, 1); funciones.splice (i, 1); } } cantTrucos = trucos.length; // Actualizar el largo máximo es innecesario, pero lo hago de todos modos. maxCars = 0; for (i = 0; i < cantTrucos; i++) { largo = trucos[i].length; if (largo > maxCars) { maxCars = largo; } } } // private static function iniciarListener ():Void { listener = new Object (); Key.addListener (listener); // listener.onKeyDown = function () { teclasPresionadas.push (String.fromCharCode (Key.getAscii ())); // Mantenemos el Array dentro del tamaño máximo para no consumir memoria if (teclasPresionadas.length > maxCars) { teclasPresionadas = teclasPresionadas.slice (-maxCars); } // Verificamos si el usuario ingresó algún truco for (i = 0; i < cantTrucos; i++) { arrayConfirmacion = teclasPresionadas.slice (-trucos[i].length); if (arrayConfirmacion.toString () == trucos[i].toString ()) { funciones[i] (); } } }; } }