Public Group

# Flash actionscript help

This topic is 2208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

(beginer) I am making a platforming game in flash and I am stuck on an action script command. Currently I have it set to have the running (single frame) movment play when the right/left key is pressed. What I am trying to do is to have it play a running animation (legs moving) while the key is pressed down. So I extended the frames of the character on the "run" sequence and added the running frames. Now when the character runs it shows the first frame, and then as soon as the character stops moving it plays the running animation. I want to just have it play from the time the key is pressed down, not just from when it comes back up. This is the code I have now
if (Key.isDown(Key.LEFT)) {

if (speed>-maxmove) {

speed--;

}
this.gotoAndPlay("run");

this._xscale = -100;
My guess would be I need to change the "Key.isDown" to something else but I dont know, thanks a lot and sorry for not knowing anything

##### Share on other sites
you need to keep track of the release/press states, essentially what you are saying now is: "while left key is down, go to the first frame of "run", then play it", and it will keep going to that first frame until you release the key.

so what you need to do is keep a variable of when you change states, like so:
 //In setup code: var LeftDown=false; //in main loop: if(Key.isDown(Key.LEFT)){ if (speed>-maxmove) { speed--; } if(LeftDown==false){ this.gotoAndPlay("run"); } LeftDown=True; }else{ LeftDown=false; //Optional gotoAndStop here } 

also, as a side note, event handlers are the way to go in flash. Edited by slicer4ever

##### Share on other sites
alright, i got it working for the most part, or enough to figure it out, thank you so much Edited by jamielightfoot

1. 1
2. 2
Rutin
21
3. 3
JoeJ
17
4. 4
5. 5

• 37
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631705
• Total Posts
3001823
×