Be a Supporter!

this.gotoAndStop. ..halp...

  • 293 Views
  • 6 Replies
New Topic Respond to this Topic
dylan-double-c
dylan-double-c
  • Member since: Mar. 5, 2008
  • Offline.
Forum Stats
Member
Level 17
Musician
this.gotoAndStop. ..halp... 2010-01-01 03:00:45 Reply

So 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.

Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to this.gotoAndStop. ..halp... 2010-01-01 03:03:24 Reply

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.

InnerChild548
InnerChild548
  • Member since: Aug. 10, 2007
  • Offline.
Forum Stats
Member
Level 35
Melancholy
Response to this.gotoAndStop. ..halp... 2010-01-01 03:03:44 Reply

Your dump's broken.


BBS Signature
HonterGames
HonterGames
  • Member since: Jun. 18, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to this.gotoAndStop. ..halp... 2010-01-01 03:04:20 Reply

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);
	}
}

BBS Signature
dylan-double-c
dylan-double-c
  • Member since: Mar. 5, 2008
  • Offline.
Forum Stats
Member
Level 17
Musician
Response to this.gotoAndStop. ..halp... 2010-01-01 03:26:37 Reply

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);
	}
}
Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to this.gotoAndStop. ..halp... 2010-01-01 03:32:40 Reply

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.

dylan-double-c
dylan-double-c
  • Member since: Mar. 5, 2008
  • Offline.
Forum Stats
Member
Level 17
Musician
Response to this.gotoAndStop. ..halp... 2010-01-01 03:40:42 Reply

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.