Stick Page Forums Archive

actionscipt help.

Started by: necros the black | Replies: 14 | Views: 1,515

necros the black
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 12, 2008 2:58 PM #90900
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
Banned

Posts: 4,311
Joined: May 2007
Rep: 10

View Profile
Mar 12, 2008 3:13 PM #90906
What are you using this for?
Raffi
2

Posts: 4,326
Joined: Aug 2006
Rep: 10

View Profile
Mar 12, 2008 4:47 PM #90918
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
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Mar 12, 2008 6:51 PM #90974
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
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 12, 2008 8:03 PM #91001
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
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Mar 12, 2008 9:37 PM #91055
ignore raffi's code, if you used that, that explains the problem.
necros the black
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 12, 2008 10:11 PM #91084
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
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
Mar 12, 2008 10:30 PM #91091
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
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 12, 2008 10:54 PM #91100
soz, still doesn't work.
Rather Cheesy
2

Posts: 2,137
Joined: Apr 2007
Rep: 10

View Profile
Mar 12, 2008 11:28 PM #91113
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
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 13, 2008 6:39 PM #91594
thanks, it's working now =D thanks to everyone for the help.
XCell
2

Posts: 123
Joined: Apr 2006
Rep: 10

View Profile
Mar 13, 2008 6:57 PM #91606
Quote from necros the black
thanks, it's working now =D thanks to everyone for the help.


that aint no smilry face
necros the black
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 13, 2008 8:06 PM #91638
??? =D is grin. anyway that wasn't the point, i was saying thanks.
Rather Cheesy
2

Posts: 2,137
Joined: Apr 2007
Rep: 10

View Profile
Mar 13, 2008 8:46 PM #91659
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
2

Posts: 142
Joined: May 2007
Rep: 10

View Profile
Mar 13, 2008 9:29 PM #91688
lol i never thought of it like that before. :)
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.