Although this may sound stupid to ask, but I don't know why I just can't make it so that when I press a key then the character would move left, and same for right... should I use actionscripts such as setproperty? or something to do with telltarget? because I tried set property and it only works once after pressing the key, afterward no matter how many times I press it, it still doesn't work...
put a button in your movie clip
then right click on the button and choose properties
the put
On (Key: <Up>)
Set Property ("", Y Position) = GetProperty ( "/player",_y )-10
End On
On (Key: <Down>)
Set Property ("", Y Position) = GetProperty ( "/player",_y )+10
End On
On (Key: <Left>)
Set Property ("", X Position) = GetProperty ( "/player",_x)-10
End On
On (Key: <Right>)
Set Property ("", X Position) = GetProperty ( "/player",_x)+10
End On
"player" is the instance name of the movie clip
in thia example
This actionscript will move the mc "player" up, down , left or right with the arrow keys.
On (Key: <Up>
Set Property ("", Y Position) = _y-10
End On
On (Key: <Down>
Set Property ("", Y Position) = _y+10
End On
On (Key: <Left>
Set Property ("", X Position) = _x-10
End On
On (Key: <Right>
Set Property ("", X Position) = _x)+10
End On
---WARNING ---
Using the Keyboard repeat rate as an animation timer will result in game inconsistency! Keyboard-repeat rate is not a constant, as the users can change the settings in their control panel, and there is no standard or default.
---WARNING ---
All games require a timer of some sort. Flash has a frame rate already, that would more then likely not line up with the keyboards rate.
The work around is quite simple:
1. Your Keyboard or UI (User Interface) sets variables that represent the Keys status.
2. A flash MC (Move Clip) would be set up to process the data thus keeping consistency in gamy play.
The Process MC would look at a Variable if (Var = Key Down) then call animation, and set Var back to default. Loop this in a “frame loop” for the best results experiment with different time delays and UI.
I hope this makes sense, because it will save you from lots of headaches down the rode.
Is there a way to tell if a key is currently down or if it's been released? For example, is there an onKeyUp event?
I'm pretty sure the answer is no, but I just gotta make sure.
No, but I think there's a tutorial on this site with a workaround... Basically involves setting a timer to trigger a keyup if a keydown hasn't been received in the last 10 frames... Too dependent on the keyboard repeat rate...
Hopefully flash 5 will solve all our problems with keyboard controls
Howdy 4eyes, In fact I dont put AS in a button just a matter of style rather I pass variables to the mc time line like Key_up=1 to trigger events. after the event the variable goes back to 0. Key_up=0. So there are 2 ways of moving your guy.
1. moves till the button is down and stops when release.
2. moves all the time you give em the direction only.