# Code walk fix

**URL:** <https://forum.kirupa.com/t/code-walk-fix/56114>\
**Category:** programming\
**Created:** [June 30, 2004, 4:48pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114 "2004-06-30T16:48:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas92](https://avatars.discourse-cdn.com/v4/letter/l/ecd19e/32.png) [@lucas92](https://forum.kirupa.com/u/lucas92)\
**Post date:** [June 30, 2004, 4:48pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/1 "2004-06-30T16:48:39Z")

</div>

Okay, so i wrote this walking code, but it isn’t working. I would post the fla, but i dont have anywhere to put it, so i will explain what i have the best i can. The problem is that i cant get the walk animation to play when i press the button, i can only get the first frame of each direction  
i have a main character movie clip with the instance name ninja. Inside there are four frames labeled t, b, r, l, and in each of these frames there is a stop action. The four mcs of the different walking directions are instance name ninjat, ninjab, ninjar, and ninjal. There are nine frames in each one. The first frame says stop, and the last frame say goto and play 2 (this is in each direction mc). Here is my code for the main ninja mc.

ActionScript:  
onClipEvent (load) {  
\_root.downwalk = true;  
\_root.upwalk = true;  
\_root.rightwalk = true;  
\_root.leftwalk = true;  
}  
onClipEvent (enterFrame) {  
if (Key.isDown(Key.RIGHT) && \_root.rightwalk == true) {  
this.gotoAndStop(“r”);  
\_root.ninjar.play();  
\_root.ninjal.play();  
\_root.ninjab.play();  
\_root.ninjaf.play();  
\_root.leftwalk == true;  
}  
if (Key.isDown(Key.LEFT) && \_root.leftwalk == true) {  
this.gotoAndStop(“l”);  
\_root.rightwalk == true;  
\_root.ninjar.play();  
\_root.ninjal.play();  
\_root.ninjab.play();  
\_root.ninjaf.play();  
}  
if (Key.isDown(Key.UP) && \_root.upwalk == true) {  
this.gotoAndStop(“b”);  
\_root.upwalk == true;  
\_root.ninjar.play();  
\_root.ninjal.play();  
\_root.ninjab.play();  
\_root.ninjaf.play();  
}  
if (Key.isDown(Key.DOWN) && \_root.downwalk == true) {  
this.gotoAndStop(“f”);  
\_root.downwalk == true;  
\_root.ninjar.play();  
\_root.ninjal.play();  
\_root.ninjab.play();  
\_root.ninjaf.play();  
}  
}  
onClipEvent (keyUp) {  
\_root.ninjab.gotoAndStop(1);  
\_root.ninjaf.gotoAndStop(1);  
\_root.ninjal.gotoAndStop(1);  
\_root.ninjar.gotoAndStop(1);  
}

Can some body help me fix this

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 2, 2004, 5:41pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/2 "2004-07-02T17:41:22Z")

</div>

just replace all the \_root’s to this in front of the ninjar, ninjal, ninjab, ninjaf. These mc’s are not located in the root but inside \_root.ninja, or because you give these actions to that ninja: this; so:

```auto
onClipEvent (load) {
	_root.downwalk = true;
	_root.upwalk = true;
	_root.rightwalk = true;
	_root.leftwalk = true;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT) && _root.rightwalk == true) {
		this.gotoAndStop("r");
		this.ninjar.play();
		this.ninjal.play();
		this.ninjab.play();
		this.ninjaf.play();
		_root.leftwalk = true;
	}
	if (Key.isDown(Key.LEFT) && _root.leftwalk == true) {
		this.gotoAndStop("l");
		_root.rightwalk = true;
		this.ninjar.play();
		this.ninjal.play();
		this.ninjab.play();
		this.ninjaf.play();
	}
	if (Key.isDown(Key.UP) && _root.upwalk == true) {
		this.gotoAndStop("b");
		_root.upwalk = true;
		this.ninjar.play();
		this.ninjal.play();
		this.ninjab.play();
		this.ninjaf.play();
	}
	if (Key.isDown(Key.DOWN) && _root.downwalk == true) {
		this.gotoAndStop("f");
		_root.downwalk = true;
		this.ninjar.play();
		this.ninjal.play();
		this.ninjab.play();
		this.ninjaf.play();
	}
}
onClipEvent (keyUp) {
	this.ninjab.gotoAndStop(1);
	this.ninjaf.gotoAndStop(1);
	this.ninjal.gotoAndStop(1);
	this.ninjar.gotoAndStop(1);
}

```

N.B. You could also make this script a lot smaller (for instance by using for-loops and arrays). Haven’t got the time right now to help you, try it, and if you need help just yell.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 2, 2004, 5:45pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/3 "2004-07-02T17:45:00Z")

</div>

oh and even a better way to shorten it, is to use the same instance name (instead of ninjab, ninjaf… use ninja\_anim) for all of them, you can do this because it’s inside a different frame. You can change

```auto
this.ninjar.play();
this.ninjal.play();
this.ninjab.play();
this.ninjaf.play();

```

to this

```auto
this.ninja_anim.play();

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 2, 2004, 5:59pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/4 "2004-07-02T17:59:10Z")

</div>

here’s your shortened version, found some time after all :geek:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 3, 2004, 4:43pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/5 "2004-07-03T16:43:02Z")

</div>

u rok all of u esp seticus. Ok maybe just seticus, but i know the rest of you would have helped if he didnt beat you to it

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2004, 9:46am UTC](https://forum.kirupa.com/t/code-walk-fix/56114/6 "2004-07-05T09:46:59Z")

</div>

pleasure helping you, sorry if I had beaten somebody (elbudster) to it…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2004, 1:34pm UTC](https://forum.kirupa.com/t/code-walk-fix/56114/7 "2004-07-05T13:34:01Z")

</div>

hehe, i couldn’t do anything anyways since i don’t have 2004 😛
