Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsOkay, I decided to switch from using the arrow keys to move my character to using the "W,A,S,D" keys instead.
What should have been a smooth transition has become a very stupid nightmare. For some odd reason, "W" and "D" work correctly, yet "A" and "S" do not.
Here is some code:
function PressAKey(event:KeyboardEvent):void
{
if(event.keyCode == 68)//d
{
rightKey = true;
}
if(event.keyCode == 65)//a
{
leftKey = true;
}
if(event.keyCode == 87)//w
{
upKey = true;
}
if(event.keyCode == 83)//s
{
downKey = true;
}
}
It worked just fine when it used the arrow keys. Only now that I tried changing it is it not working completely.
(This code is from a tutorial on Youtube)
Did you set up your event right?
Something like this:
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
function onKeyPressed(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case 87:
upKey = true;
break;
case 65:
leftKey = true;
break;
case 83:
upKey = true;
break;
case 68:
downKey = true;
break;
default:
//wrong key was entered
break;
If a structure like that isn't smooth, try declaring your used variables private. Another piece of of code right be affecting them. You can set gettings/setters if you need them to be public.
Make sure you have keyboard shortcuts disabled.
From the swf window in flash. Control -> Disable keyboard shortcuts.
At 4/28/12 06:37 AM, 4urentertainment wrote: Make sure you have keyboard shortcuts disabled.
From the swf window in flash. Control -> Disable keyboard shortcuts.
That did it. Thanks!