A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: KEY_DOWN Problems

  1. #1
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196

    Cow Icon KEY_DOWN Problems

    Hey everyone! I have a virtual joystick that I am making for one of my games, and I'm having a problem with the KEY_DOWN command. Here's my code so far.

    Code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, joyKeyDown);
    stage.addEventListener(KeyboardEvent.KEY_UP, joyKeyUp);
    
    function joyKeyDown(joyEventGo:KeyboardEvent):void {
    	if (joyEventGo.keyCode==Keyboard.LEFT) {
    		joystick.gotoAndPlay(2);
    	}
    }
    
    function joyKeyUp(joyEventStop:KeyboardEvent):void {
    	if (joyEventStop.keyCode==Keyboard.LEFT) {
    		joystick.gotoAndPlay(1);
    	}
    }
    My problem is that I cant seem to get it to stop looping. I have a joystick in normal position in frame 1 of the joystick MC, and other positions in the other 4 frames.

    Here's what my code makes the joystick do.

    \ / \ / \ / \ / \ / \ / \ / \

    it flashes back and forth. I cant get it to stop pinging the function for gotoAndPlay, so it wont stop going to the right position.


    Can someone please fix my code?


    Thanks, Xen Element
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  2. #2
    Senior Member
    Join Date
    May 2009
    Posts
    138
    Have you tried gotoAndStop()?

  3. #3
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Wow. It didn't work before, but I just tried it now and it worked! Thanks so much!
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  4. #4
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    The answer was, gotoAndStop(), because the stop part does not override the stop already in the MC frame like the gotoAndPlay() did.

    Thank you very much, I can't believe I didn't see this before!
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You probably want gotoAndStop instead of gotoAndPlay.

    Also, if you are holding down your key, then the operating system will start sending repeated keypresses after a short delay. You could remove the listener until the KeyUp is detected.

    Edit:

    I'm slow on the draw today.

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