The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.

ForumsProgramming ForumMoving in AS3

5 4242
ExplosionsHurt
offline
ExplosionsHurt
248 posts
Nomad

I have a stupid question, but I'm trying to move a character using the arrow keys. I know that (thanks to a tut in this forum) key.IsDown() does it in AS2, but how can I do it in AS3?

Any help would be appreciated.

  • 5 Replies
gaboloth
offline
gaboloth
1,612 posts
Peasant

Sadly no, there is no key.IsDown property in as3. You need to make your own. Basically you set some event listeners that detect when keys get pushed or lifted, you make a Boolean for each key and you turn it on when the player pushes the key and turn it off when he lifts it.
I used this tutorial and it works, but he does some... weird things. I would do some google searches before if I were you.

master565
offline
master565
4,104 posts
Nomad

I use a set of booleans.

I have a keydown function where i use a keycode method to check if a key is down and if it is then i change a boolean to (the key) isdown=true

Then in a keyup function i have (the key) isdown=false

then in an enter frame function, i check
[quote]
if (the key) isdown == true)
{
movieclip.x += (direction
}

ExplosionsHurt
offline
ExplosionsHurt
248 posts
Nomad

oh, that makes sense. Thanks

PixelSmash
offline
PixelSmash
566 posts
Nomad

stijn: I believe this is AS2, the on(function) stuff was removed in AS3.

Other than that: when I need to, I usually use something along the lines of master's implementation. Works like a charm!

Cheers!

Showing 1-4 of 5