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 6661363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:14+00:00 2026-05-26T02:16:14+00:00

I was trying to make a tank game in which I can move the

  • 0

I was trying to make a tank game in which I can move the tanks, let them shoot each other, etc… I insist on creating external classes with Flash Pro cause I am used to OOP language like Java. I created a Tank class which represents all the tanks. Here is the code of this class:

package src
{
    import flash.display.MovieClip;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

    public class Tank extends MovieClip 
    {       
        public function Tank():void {           
            this.addEventListener(KeyboardEvent.KEY_DOWN, move);
            this.addEventListener(MouseEvent.CLICK, test);
        }
        protected function move(event:KeyboardEvent):void {
            trace("key down");
            switch (event.keyCode) {
                case Keyboard.UP: {
                    this.y += -5;                   
                    break;
                }
                case 40: {
                    this.y += 5;                    
                    break;
                }
                case Keyboard.LEFT: {
                    this.x += -5;                   
                    break;
                }
                case Keyboard.RIGHT: {
                    this.x += 5;                    
                    break;

                }

            }
        }

    }

}

The problem is that the action listener seems never get called when I press any keys. the trace() is not called. But I tried to add a mouse listener just to test and it worked. So I guess its the Keyboard event listener class’s problem? Everyone I see on the web uses stage.addEventListener(KeyboardEvent.KEY_DOWN, move) approach.

Could anyone tell me why it’s not working? And are there any solutions?(only by adding external classes, please) Thank you!

  • 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-05-26T02:16:15+00:00Added an answer on May 26, 2026 at 2:16 am

    Try adding your key listeners to stage.

    stage.addEventListener(KeyboardEvent.KEY_DOWN, move);

    Stage will always be able to detect key events when your application is in focus.

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

Sidebar

Related Questions

trying to make 5 curl childs for curl handler and defining them, but can't
Im making a 2D game where the player controls a tank. I can make
Trying to make a document viewer, like Acrobat, which consists of pages, and each
I'm trying make an entity with doctrine that has three associations with other entities
I am fairly new to iOS development and trying make a simple app which
Trying to make an xna game, where the user needs to tap to stop
I'm trying make a report which contains some prices on every row, and I
Trying to make a simple toggle menu, and I can't seem to hide/show the
I am trying make such application which speak automatically when the image loaded it
I'm trying make one treeView with infinite subgroups. I can add my groups but

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.