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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:24:51+00:00 2026-05-12T00:24:51+00:00

Okay, I’ve tried about 8 different ways to get a key event into my

  • 0

Okay, I’ve tried about 8 different ways to get a key event into my code, and none of them seem to work. Can someone please tell me how I can move this ball when I press shift? Thank you in advance

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
  styleName = "plain"
    xmlns="cyanprime.*" 
    layout="absolute"
    width="600"
    height="400"
    frameRate="100"
    creationComplete="initApp()">

    <mx:Script>
        <![CDATA[
            public function initApp():void
            {

                Mouse.hide();
                canvas.init();
                canvas.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
            }

            private function keyDown(event:KeyboardEvent):void
            {
                canvas.KeyDownHandler(event);
            }
        ]]>
    </mx:Script>

  <MyGameCanvas id="canvas" width="100%" height="100%" themeColor="#ff000000" />
</mx:Application>

…

package cyanprime{

    import mx.core.UIComponent;
    import mx.controls.Image;
    import flash.events.*;
    import flash.utils.*;
    import flash.display.*;
    import flash.ui.Keyboard;

    public class MyGameCanvas extends UIComponent{
        [Embed(source="player.gif")]
        private var playerImage:Class;

        private var player:DisplayObject = new playerImage();
        private var player_x:Number;
        private var player_y:Number;
        private var ticker:Timer;



        public function init():void{
            // set up player
            addChild(player);

            ticker = new Timer(10); 
            ticker.addEventListener(TimerEvent.TIMER, onTick);
            ticker.start();

        }

        public function KeyDownHandler(event:KeyboardEvent):void{
            if(event.keyCode == Keyboard.SHIFT)
            player_x += 50;
        }

        public function onTick(evt:TimerEvent):void {
        }       
    }
}
  • 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-12T00:24:52+00:00Added an answer on May 12, 2026 at 12:24 am

    you need to add the listener to the stage, and ad it after the applicationComplete event has occured (or in its handler)

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
     <mx:Script>
        <![CDATA[
    
        public function init():void
        {
            trace('Initialization');
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);    
        }
    
        private function keyDown(event:KeyboardEvent):void
        {
            trace(event.charCode);
        }       
        ]]>
     </mx:Script>
    </mx:Application>
    

    ref

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

Sidebar

Related Questions

Okay, none of the previous questions I have seen with this error seem to
Okay, I'm reading about Linux kernel development and there are some code snippets using
Okay, so I know how to get a list of accounts so that I
Okay, so I've done a bit of research into using PHP to allow using
Okay so my question is this. Say I have a simple C++ code: #include
Okay, I'll say now that I know very little about Java. I was given
Okay, so I did all the research for this issue but none of the
Okay, I've been messing around with the excellent JodaTime library, attempting to get a
Okay, so I've known about this for like 600 years now, but I've only
Okay, so I've tried to use sort to vector of items so the size

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.