A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: is it possible to make a dual key press perform a single action?

  1. #1
    Junior Member
    Join Date
    May 2005
    Posts
    4

    Question is it possible to make a dual key press perform a single action?

    im trying to make a game that requires you to have the spacebar and the right arrow key pressed to make the character move. However i just cant seem to link the 2 key presses together.

    when the keys are pressed individually it works and when theyre pressed together it works but i want the character to be inactive until both are down at the same time :/

    i've tried everything that i can think of (which is kinda limited) i thought id cracked it with a 'while' statement but when i tested it flash would throw a fit and close

    heres the code that flash doesnt like, it looks (to me) like it should work but it clearly doesnt :P
    PHP Code:
    onClipEvent (load) {
        
    _x 0;
        
    _y 0;
    }
    onClipEvent (keyDown) {
        if (
    Key.isDown(Key.SPACE)) {
            while (
    Key.isDown(Key.RIGHT)) {
                
    _x += 1;
                
    _y -= .4;
            }
        }

    any help on this matter would be greatly appreciated, and if its not even possible then im glad i asked or id have been there all week

    cheers
    wannabe flash master :P

  2. #2
    Junior Member
    Join Date
    Nov 2008
    Posts
    11
    Try using &&:

    onClipEvent (keyDown) {
    if (Key.isDown(Key.SPACE) && Key.isDown(Key.RIGHT)) {
    _x += 1;
    _y -= .4;
    }
    }

  3. #3
    Junior Member
    Join Date
    May 2005
    Posts
    4
    HaHa it worked! thanks for that.
    it was so simple im kicking myself for not figuring it out lol
    wannabe flash master :P

Tags for this Thread

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