Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:45:48+00:00 2026-06-07T01:45:48+00:00

I have 2 eventListeners: 1) key listener(A, S, D ,W); – for move object

  • 0

I have 2 eventListeners:

1) key listener(A, S, D ,W); – for move object

2) key listener(WhiteSpace) – for jump object

so when i have pressed the A OR S OR D OR W keys then i press the whitespace to before this moment its all okey, the object is moving and jumping at the same time, but if i release the whitespace key while moving, the object stops…

so how can i make that when i release the key white space, the object will still moving?? don’t paying attention to the other key releasing or pressing?

private function onKeyDown(e:KeyboardEvent):void {

    //trace(e.keyCode);
    switch(e.keyCode)
    {

    case 68:
    direction = 'left';
    stage.addEventListener(Event.ENTER_FRAME, moveRight);
    break;
    case 65:
    direction = 'right';
    stage.addEventListener(Event.ENTER_FRAME, moveLeft);
    break;
    case 32:
    jump() // the whitespace key
        break;

    }

private function moveRight(e:Event):void {

shape.x += 5;

}

private function moveLeft(e:Event):void {

shape.x += 5;

}

private function jump():void {

    stage.addEventListener(Event.ENTER_FRAME, jumpAnimation);
}

private function jumpAnimation(e:Event):void {

   //here code for jumping increasing the y and decreasing....
}

private function onKeyUp(e:Event):void {


    stage.removeEventListener(Event.ENTER_FRAME, moveRight);
    stage.removeEventListener(Event.ENTER_FRAME, moveLeft);


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:45:50+00:00Added an answer on June 7, 2026 at 1:45 am

    You could implement a key up/down listeners and an enter frame listener and use some booleans to indicate what keys are down and update accordingly. Something like this might work:

    var keyMap:Dictionary = new Dictionary();
    
    addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
    addEventListener( KeyboardEvent.KEY_UP, onKeyUp );
    addEventListener( Event.ENTER_FRAME, onEnterFrame );
    
    function onKeyDown( event:KeyboardEvent ):void 
    {
        keyMap[ event.keyCode ] = true;
    }
    
    function onKeyUp( event:KeyboardEvent ):void 
    {
        keyMap[ event.keyCode ] = false;
    }
    
    function onEnterFrame( event:EnterFrame ):void 
    {
        if( keyMap[ 68 ] ) 
        {
            // -- move left
        }
    
        if( keyMap[ 65 ] ) 
        {
            // -- move right 
        }
    
        // -- ect...
    }
    

    This would avoid a situation where one key up is causing all other keys from firing continuously because you would only be relying on a single key up or down from each key. The code to update your scene would be running continuously.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have a class which generates events e.g. public class EventSource{ public addEventListener(EventListener listener).....
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have used this code in my AS3 document class to remove all objects
somewhat simple problem(to explain) this time: i have an array of markers that i
I have written the following function which adds an event listener and registers the
i have a list of items containig names. then i have a eventlistener, which
So I have a problem where the eventlisteners I setup all happen to work
Do you have to remove event listeners on variables with local scope? By this
On every object in my DB, I have audit fields for CreatedBy, CreatedOn, ModifiedOn,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.