A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [Help] Keystroke - More then once per hit?

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    [Help] Keystroke - More then once per hit?

    Hey everyone,

    I just have a question. This has always been a problem when I make things in flash , in this case a game, and it really fustrates me

    If you use the whole "if (Key.isDown(Key.SHIFT))" or any key for that matter , flash considers it being pressed more then once when you clearly only pressed it once.
    This is because it considered it pressed down constantly when you hold the key down , but it happens so fast that it seems to you as the user that you only pressed the key down simply once


    This might not be a problem in most cases, but unfortunatly for me Im not part of that catagory. My problem is this:


    1) Im making a platform game, but there are two characters in it. When you press the shift button, it will go to the other character and vice versa.

    2) There is a _root.player = false; variable. False being the red character and true being the blue one

    3) When you press the shift button, the variable should simple just change back and forth between true and false

    4) But since Flash considers what seems to be one easy hit of the shift key a bunch of keystrokes, the _root.player variable changes between true and false numerous times sometimes causing it to land back on what it was originally



    Anyways, if someone could help me out here it'll be greatly appreciated as always
    Last edited by Osteel; 11-18-2005 at 11:21 AM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Could you to use the 'up' instead of 'down' ? This would eliminate the problem.

    Code:
    stop();
    var keyListener:Object = new Object();
    keyListener.onKeyUp = function() {
    	trace("UP -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
    };
    Key.addListener(keyListener);

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Thanks dawson,

    Ill try it out in a bit

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center