PDA

View Full Version : actionscipt help.



necros the black
03-12-2008, 08:58 AM
i know i'm probably making a stupid misrtake but i'm having an actionscript problem. i'm using this code

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x-=3;
this.gotoAndPlay(2);
}
}

there's some more but just the same repeated for different directions. jnow the movement works perfectly so when i press left it goes left but the movie clip only goes to frame 2 and plays after i let go of the key. so it moves left then when it stops moving the movieclip runs a taking a step animation.
how do i make it run the taking the step animation at the same time as moving?

Chunky
03-12-2008, 09:13 AM
What are you using this for?

Raffi
03-12-2008, 10:47 AM
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x-=3;
this.gotoAndPlay(2);
}
}
There's your problem. It's been set to play from frame 2. To stop this, you need gotoandStop.

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x-=3;
this.gotoAndStop(2);
}
}

Scorpioxxx
03-12-2008, 12:51 PM
your code is right, but, you need something like;

(in frame 2)

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this.play;
} else {
this.gotoAndstop(1);
}
}

to make it go back to frame one if the button ain't being pressed.

necros the black
03-12-2008, 02:03 PM
kk, i can make the clip play at the same time now, but if press left so he walks left, the clip just keeps playing or doesn't work the second time i press it? what do i do?

Scorpioxxx
03-12-2008, 03:37 PM
ignore raffi's code, if you used that, that explains the problem.

necros the black
03-12-2008, 04:11 PM
no the problem now is that when it goes to frame 2 and stays there even when i let go of the key. so the legs keep walking. how do i make it so when i let go of the key is returns to frame one?
oh i already tried your earlier code on the second frame.
if i send you the flash file can you help?

The Pirate
03-12-2008, 04:30 PM
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x-=3;
gotoAndPlay(2);
} else {
gotoAndStop(*whatever your standing still frame is*)
}
}

Ehhh, I think that should work. It's actually been a while since I've had to use an "else" statement in actionscript, as trivial and common of a piece of code as that may seem.

necros the black
03-12-2008, 04:54 PM
soz, still doesn't work.

Rather Cheesy
03-12-2008, 05:28 PM
Your code must be in the the frame at all times, so if you have the code on frame 1 then when you press that button, it goes to frame 2, then it won't work again till it gets back to frame 1 because thats where the code is.

The way I code my games is I have one movieclip for the character then in that movieclip asre the movement movieclips on per frame. each frame is coded for the percise button needed to press to play the animations in them, not to move them. Then on the document I add that movieclip and put the codes for movement on it along with which frame the movieclip needs to go to play that animation

so it would go like this

on the root there is a movieclip. It is told when you press left the go to and stop at frame 2 if the left button is not pressed then it goes and stops on frame 1. In frame 2 of that movie clip is a run animation movieclip. its first frame is set to stop. the code says that if your press left then it should play. If not then it should go to and stop at frame 1 that plays the animation when you press left. then on the movieclip that contains the run movieclip you need to add your movement code to it to make it move as it plays the animation.

I'm to lazy to add the exact codes needed but their all basic codes used together.

necros the black
03-13-2008, 12:39 PM
thanks, it's working now =D thanks to everyone for the help.

XCell
03-13-2008, 12:57 PM
thanks, it's working now =D thanks to everyone for the help.

that aint no smilry face

necros the black
03-13-2008, 02:06 PM
??? =D is grin. anyway that wasn't the point, i was saying thanks.

Rather Cheesy
03-13-2008, 02:46 PM
He's joking, he means that it looks like the end of a penis... Just put an eight at the begining of =D and it looks like one. Best stick with :D instead.

necros the black
03-13-2008, 03:29 PM
lol i never thought of it like that before. :)