A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [HELP] ActionScript 2: Prevent doubling an action when two keys are pressed together

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    23

    Question [HELP] ActionScript 2: Prevent doubling an action when two keys are pressed together

    I'm in the very early stages of developing a platform game in Flash CS3 using ActionScript 2. Previously, I've always just instructed the player to use the WASD keys to control the player. In this game, I'm adding the possibility to use either WASD or arrow keys.

    The problem that I've run into, is that when two keys that perform the same action (the right arrow and "d" key for example) the action is performed twice. How can I disable one key if the other is being pressed?

    Here's the code I'm working on: http://pastie.org/9665826[1]

    Any tips?

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    replace
    PHP Code:
    if (Key.isDown(Key.RIGHT)){
        
    _x += speed;
    }
        
    if (
    Key.isDown(68)){
        
    _x += speed;

    with
    PHP Code:
    if (Key.isDown(Key.RIGHT) || Key.isDown(68)){
        
    _x += speed;

    who is this? a word of friendly advice: FFS stop using AS2

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