Walking Problem In ActionScript 2

Started by: Ahtex! | Replies: 4 | Views: 525

Ahtex!

Posts: 427
Joined: Dec 2007
Rep: 10

View Profile
Mar 1, 2010 11:18 PM #552288
http://filebox.me/view/tvjbu0ku5

i got the walking part down, i just seem to figure out how to get him to stop moving his arms when no button is pressed, and remain facing the direction he is facing.

Code:
onClipEvent(load){
this.stop();
speed = 3;
motion = 0;
}
onClipEvent(enterFrame){
if (Key.isDown){
motion = 1
}
else{
motion = 0
}
if (motion = 1){
if (Key.isDown(Key.DOWN)){
this._y += speed;
this.gotoAndStop( 2 );
this._xscale = 100
this._yscale = 100
}
if (Key.isDown(Key.UP)){
this._y -= speed;
this.gotoAndStop( 2 );
this._xscale = 100
this._yscale = -100
}
if (Key.isDown(Key.LEFT)){
this._x -= speed;
this.gotoAndStop( 3 );
this._xscale = -100
this._yscale = 100
}
if (Key.isDown(Key.RIGHT)){
this._x += speed;
this.gotoAndStop( 3 );
this._xscale = 100
this._yscale = 100
}
}
if (motion = 0){
this.gotoAndStop(1);
}
}


Additional Note:
the frame numbers in the MC are as follows
1: Idle
2: Run Vertical (facing Down without script)
3: Run Horizontal (facing Right without script)

Edit: Fixed, i put another code on the MC within the MC to control the animation movements when the respective keys are pressed. Something i should have done anyways. If i have any more problems i'll be sure to post them!

http://filebox.me/view/a5f1cpyrs
Bonk
2

Posts: 2,778
Joined: Mar 2008
Rep: 10

View Profile
Mar 2, 2010 9:39 AM #552411
Ah, simple.
In all of the "if"s makes sure it is

==


instead of a single one. A single equal sign changes the variable appropriately when the "if" is run even though it is within the "if".

example:


if (motion == 0){
this.gotoAndStop(1);
}
Ahtex!

Posts: 427
Joined: Dec 2007
Rep: 10

View Profile
Mar 2, 2010 10:10 AM #552416
im not quite sure what you mean, ive inputed it into the code how i thought u meant but it doesn't work. maybe ive put it in wrong:
onClipEvent(load){
this.stop();
speed = 3;
motion = 0;
}
onClipEvent(enterFrame){
if (Key.isDown){
motion = 1
}
else{
motion = 0
}
if (motion == 1){
if (Key.isDown(Key.DOWN)){
this._y += speed;
this.gotoAndStop( 2 );
this._xscale = 100
this._yscale = 100
}
if (Key.isDown(Key.UP)){
this._y -= speed;
this.gotoAndStop( 2 );
this._xscale = 100
this._yscale = -100
}
if (Key.isDown(Key.LEFT)){
this._x -= speed;
this.gotoAndStop( 3 );
this._xscale = -100
this._yscale = 100
}
if (Key.isDown(Key.RIGHT)){
this._x += speed;
this.gotoAndStop( 3 );
this._xscale = 100
this._yscale = 100
}
}
if (motion == 0){
this.gotoAndStop(1);
}
}


also i think the problem may lie in line 7
if (Key.isDown){

because i mean for it to be activated when any key is pressed.
Bonk
2

Posts: 2,778
Joined: Mar 2008
Rep: 10

View Profile
Mar 2, 2010 10:35 AM #552419
Yeah I've never seen that before...

couldn't you just insert the "motion = 1;" in each of the four direction actions? It would eliminate the first little bit and that bogus Key.IsDown

Also, the last "if" could just be an "else" of the "if (motion == 1) {}" above it. Sometimes little things like that make a difference.
Ahtex!

Posts: 427
Joined: Dec 2007
Rep: 10

View Profile
Mar 3, 2010 10:12 PM #552778
Fixed the problem, thanks for your help bonk but it was to do with the animation inside the Movie Clip. I can simultaneously control the movement and animation with one key press now so it isn't an issue!