Results 1 to 4 of 4
Thread: sequence keypress
-
March 29th, 2012, 06:11 PM #133Registered User
postssequence keypress
AS2- I have a simple key is down actionscript what i am trying to do is make it a multi 'key is down' so instead of pressing ''G'' to open frame 2 a person has to type a full word for example they would need to type the word ''frame2'' on their keybored to open frame 2 instead of pressing one key, Thanks in advance!
(Typed as a sequence NOT holding all the keys at once)
function onEnterFrame()
{
if (Key.isDown(71))
{
gotoAndStop(2);
} // end if
} // End of the function
stop ();
-
March 29th, 2012, 08:02 PM #21,391Registered User
postswell it's a bit complex but how about something like this - any code placed in the codes array will be checked for - but you must also create a 'case' statement to handle that particular code (there are other ways to make this assignment dynamic)
you can run this by placing in in the first frame of a new doc - note that this is case sensitivePHP Code:var record:String = "";
var codes:Array = [ "check" ];
var keyboard:Object = new Object();
keyboard.onKeyDown = checkCodes;
Key.addListener( keyboard );
function checkCodes():Void {
if( Key.getCode() != Key.SHIFT && Key.getCode() != Key.CAPSLOCK ) {
record += (Key.isDown(Key.SHIFT) || Key.isDown(Key.CAPSLOCK)) ? String.fromCharCode(Key.getCode()).toUpperCase() : String.fromCharCode(Key.getCode()).toLowerCase();
trace( record );
}
for( var c in codes ) {
if( record.indexOf( codes[c] ) == -1 ) continue;
trace( "[FOUND CODE] " + codes[c] );
switch( codes[c] ) {
case "check":
trace( "CHECK RESPONSE" );
break;
case "frame1":
gotoAndStop(1);
break;
case "frame2":
gotoAndStop(2);
break;
default:
break;
}
record = "";
break;
}
if( record.length > 100 ) record = record.slice(0,100);
}
-
March 29th, 2012, 08:09 PM #333Registered User
postsIv solved it a simpler way like this:
var char:String = new String();
var input:String = new String();
var reference:String = new String("test1");
var keyLis:Object = new Object();
keyLis.onKeyDown = function(){
char = String.fromCharCode(Key.getAscii()).toLowerCase();
input += char;
if(input.length>=reference.length){
input = input.substr((input.length-reference.length),reference.length);
if(input==reference.toLowerCase()){
trace("SUCCESS");
gotoAndStop(2);
}
}
}
Key.addListener(keyLis);
stop();
then on the 2nd frame i have this so you can type in another word to get to the next frame :
var char2:String = new String();
var input2:String = new String();
var reference:String = new String("test2");
var keyLis:Object = new Object();
keyLis.onKeyDown = function(){
char2 = String.fromCharCode(Key.getAscii()).toLowerCase();
input2 += char2;
if(input.length>=reference.length){
input = input.substr((input.length-reference.length),reference.length);
if(input==reference.toLowerCase()){
trace("SUCCESS2");
gotoAndStop(3);
}
}
}
Key.addListener(keyLis);
stop();
-
March 29th, 2012, 11:49 PM #41,391Registered User
postsi'm sorry, but i would have to say it's not really 'simpler' - you'll have to repeat the script on every navigation frame and change the values - with the above(or now below) you only have to enter the code and a response case - and you could remove the response case switch if your simply advance frame to frame where you can use the code index to navigate the timeline - i've also removed the case sensitivity in the below:
placed on frame 1, this one pieces of script will handle all navigation - simply type in the next 'password' in to the codes array for the related frame (remember that arrays are 0 based)Code:var record:String = ""; var codes:Array = [ "frame2","frame3","frame4" ]; var keyboard:Object = new Object(); keyboard.onKeyDown = checkCodes; Key.addListener( keyboard ); function checkCodes():Void { record += String.fromCharCode(Key.getCode()).toLowerCase(); for( var c:int=0; c<codes.length; c++ ) { if( record.indexOf( codes[c] ) == -1 ) continue; gotoAndStop( c+1 ); record=""; break; } if( record.length > 100 ) record = record.slice(0,100); }
additionally, you can type *any* of the codes at *any* time, and it will navigate to the related frame position - this is not possible with your other method since each frame holds individual scripts that are specific to the frame (however, it may be that since the other listeners are not being removed they may function similarly)Last edited by cbeech; March 29th, 2012 at 11:54 PM.

Reply With Quote

Bookmarks