This content has been marked as final. Show 6 replies
The code is a mess! if you found this code somewhere on the internet, then I suggest you start looking for better sources.
If you wrote it yourself, you need work on your syntax. Look for some beginning actionscript tutorials (try kirupa.com, or gotoandlearn.com).
The attached code sample is what your code should look like.
In my poor understanding of boolean logic, that corrected script doesn't make any sense. The first "if" captures all events. What is the second "if" for? I think "else if" would be appropriate here otherwise the gotoAndPlay(2) will not execute for the left arrow key as the second if block will force it back to frame 1.
And BTW, I'm not sure why you want a gotoAndPlay(2). If there is anything beyond frame 2 (i.e. frame 3 or more and implied by the "play"), it will never get there as holding the left or right arrow keys down will continue to send the clip to frame 2 because the onEnterFrame never stops running. Maybe this is the effect you want but it is a bit inefficient.
The onEnterFrame continues to run regardless of whether you are pressing a key or not. So What about placing the script in a keyframe in the timeline rather than on the clip itself. As an example, I named the clip that will move left or right "myclip".
Or if you really want to place the script on the clip itself rather than in the timeline, the equivalent script would be
if this would help you, I wanted to create a walking animation for a game, but (offcourse) I dont want the legs to move if its not walking
Well I'm not really sure how that helps me but if that is the case then you most definitely want to delete the onEnterFrame when the key is raised. That script I posted with the two key listeners is pretty much what you need. The walking animation will be controlled entirely by your movieclip that is playing while you are moving.