The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: sequence keypress

  1. #1

    sequence 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 ();

  2. #2
    1,391
    posts
    Registered User
    well 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)
    PHP Code:
    var record:String "";
    var 
    codes:Array = [ "check" ];

    var 
    keyboard:Object = new Object();
    keyboard.onKeyDown checkCodes;

    Key.addListenerkeyboard );

    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();
            
    tracerecord );
        }
        
        for( var 
    c in codes ) {
            if( 
    record.indexOfcodes[c] ) == -) 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);

    you can run this by placing in in the first frame of a new doc - note that this is case sensitive

  3. #3
    Iv 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();

  4. #4
    1,391
    posts
    Registered User
    i'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:
    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);
    }
    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)

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012