The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.36 / 5.00 33,851 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 12,195 ViewsSo I'm trying to get my character to look in the direction it is moving. At first it worked, but then I remembered that I need to stop the walking animation when the movement key is up.
This is the code.
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(4);
this._x -= 3;
else
this.gotoAndStop(3);
}
}
// change code as needed to support direction
The only part that is going wrong is the "else" part.
Could I get a little help?
I Dump'd it.
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(4);
this._x -= 3;
}else this.gotoAndStop(3);
}
// change code as needed to support direction
The else statement goes after the ending brace.
Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(4);
this._x -= 3;
}else{
this.gotoAndStop(3);
}
}
Oh and some ppl (eg, Archon hahahaha ;D) are likely gonna say code on timeline so
this.onEnterFrame = function(){
if(Key.isDown(Key.LEFT)){
MCname.gotoAndStop(4);
MCname._x -= 3;
}else{
MCname.gotoAndStop(3);
}
}
At 1/1/10 03:03 AM, Montycarlo wrote: The else statement goes after the ending brace.
Oh, wow...I didn't even consider that...Thanks
...
Once I tried it with the following code, I resulted with this.
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(4);
this._x -= 3;
}
}
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this.gotoAndStop(2);
this._x += 3;
}else{
this.gotoAndStop(3);
}
} At 1/1/10 03:26 AM, dylan-double-c wrote: Once I tried it with the following code, I resulted with this.
Without even looking at the link, I can see your problem.
First of all, why are you using two onClipEvent(enterFrame) handlers? That's absolutely pointless. Merge them.
Your problem lies in the separation and execution-order of the if statements. The first statement, checks if the left key is down, if it is down, it changes the frame to 4 and shifts the object 3 places to the left. Then, following, in the second onClipEvent(enterFrame) handler you have another if statement checking if the right key is down, followed by an else statement. This is your problem. Your else block is executed regardless of if the left key was down or not.
To solve this, merge the handlers together, and 'chain together' the if statements, to create a if-else cause line.
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(4);
this._x -= 3;
}else if(Key.isDown(Key.RIGHT)){
this.gotoAndStop(2);
this._x += 3;
}else{
this.gotoAndStop(3);
}
} Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.
At 1/1/10 03:32 AM, Montycarlo wrote: First of all, why are you using two onClipEvent(enterFrame) handlers? That's absolutely pointless. Merge them.
Yeah, my bad. I haven't slept in, like...36 hours or something like that. Scripting is the last thing I need to be doing. Also, thanks. It worked.