Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Key is down/Key press help

  1. #1

    Key is down/Key press help

    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!
    function onEnterFrame()
    {
    if (Key.isDown(71))
    {
    gotoAndStop(2);

    } // end if
    } // End of the function
    stop ();

  2. #2
    Type as a sequence or holding all the keys at once?
    Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.

  3. #3
    Typing as a sequence so....
    f pressed CHECK
    r pressed CHECK
    a pressed CHECK
    ..................
    e pressed CHECK, START... GotoAndStop(2)

  4. #4
    some psudocode
    Code:
    var typeseq:Number;
    
    if(key.isDown(yourkeycode)){
       typeseq = 1
    }
    if(typeseq == 1){
       if(key.isDown(yourkeycode)){
         typeseq = 2
       }
    }
    if(typeseq == 2){
       if(key.isDown(yourkeycode)){
         typeseq = 3
       }
    }
    //...so on
    //
    there are other ... probably better ways to do it. But this is simple to understand.
    Last edited by GabeLaneG; March 29th, 2012 at 06:13 PM.
    Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.

  5. #5
    Arh nice but how would i Implement the gotoAndStop(2) into the script ?

  6. #6
    After the end of the sequence, reset typeseq to 0 and add your gotoAndStop after that line..

    Code:
    if(typeseq == 5){
          if(key.isDown(yourkeycode)){
              typeseq = 0
              _root.gotoAndStop(frame)
          }
    }
    Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.

  7. #7
    So the code in full would look like this :

    var typeseq:0;


    if(key.isDown(70)){
    typeseq = 1
    }
    if(typeseq == 1){
    if(key.isDown(71)){
    typeseq = 2
    }
    }
    if(typeseq == 2){
    if(key.isDown(72)){
    typeseq = 3
    }
    }
    if(typeseq == 3){
    if(key.isDown(73)){
    typeseq = 4
    }
    }
    if(typeseq == 4){
    if(key.isDown(74)){
    typeseq = 5
    }
    }
    if(typeseq == 5){
    if(key.isDown(75)){
    typeseq = 0
    _root.gotoAndStop(2)
    }
    }

  8. #8
    yeah, around that. but I wouldn't set typeseq to 0 every frame at the start like that, it probably won't work.
    Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.

  9. #9
    Nope doesnt work i tryed different numbers instead of 0 aswel ohwell thanks for the help!
    i went with this

    var typeseq; 11;




    if(key.isDown(70)){
    typeseq = 1
    }
    if(typeseq == 1){
    if(key.isDown(71)){
    typeseq = 2
    }
    }
    if(typeseq == 2){
    if(key.isDown(72)){
    typeseq = 3
    }
    }
    if(typeseq == 3){
    if(key.isDown(73)){
    typeseq = 4
    }
    }
    if(typeseq == 4){
    if(key.isDown(74)){
    typeseq = 5
    }
    }
    if(typeseq == 5){
    if(key.isDown(75)){
    typeseq = 11
    _root.gotoAndStop(2)
    }
    }
    stop();
    Last edited by MAGG0T; March 29th, 2012 at 06:49 PM.

  10. #10
    heres the fla for anyone to have a go
    Attached Files Attached Files

  11. #11
    Change " var typeseq; 11;" to "var typeseq:Number;".
    Don't actually set Number to a number ...
    Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.

  12. #12
    1,391
    posts
    Registered User
    from the other thread
    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);
    }

  13. #13
    64
    posts
    Registered User
    hi cbeech, how can i try out your code. is there a fla that comes with this code so that i may try it. i am using flash 8. i simply copied and pasted the code in a blank file and tried running it but got an error message. how can the record string be displayed so that we may see what keys were pressed or are being pressed.
    Thanks.
    Last edited by ajoo; April 22nd, 2012 at 01:58 PM.

  14. #14
    64
    posts
    Registered User
    hi cbeech, how can i try out your code. is there a fla that comes with this code so that i may try it. i am using flash 8. i simply copied and pasted the code in a blank file and tried running it but got an error message. how can the record string be displayed so that we may see what keys were pressed or are being pressed.
    Thanks.

  15. #15
    hi you just write _root.gotoAndPlay(2); but u are at the currect level so you don`t need to go to _root
    Just at the end write gotoAndPlay(2); or use this code:

    stop();
    var typeseq:Number = new Number;




    keyListener = new Object();
    keyListener.onKeyDown = function() {


    if(Key.getCode()==70){
    typeseq = 1

    }
    if(typeseq == 1){
    if(Key.getCode()==71){
    typeseq = 2
    }
    }
    if(typeseq == 2){
    if(Key.getCode()==72){
    typeseq = 3
    }
    }
    if(typeseq == 3){
    if(Key.getCode()==73){
    typeseq = 4
    }
    }
    if(typeseq == 4){
    if(Key.getCode()==74){
    typeseq = 5
    }
    }
    if(typeseq == 5){
    if(Key.getCode()==75){
    typeseq = 6
    gotoAndStop(2)
    }
    }
    }
    Key.addListener(keyListener);

Page 1 of 2 12 LastLast

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