# Controlling a movie clip (playing forward & backward) with multiple buttons

**URL:** <https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237>\
**Category:** flash\
**Created:** [June 4, 2008, 11:17am UTC](https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237 "2008-06-04T11:17:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bottleHeD](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bottleHeD](https://forum.kirupa.com/u/bottleHeD)\
**Post date:** [June 4, 2008, 11:17am UTC](https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237/1 "2008-06-04T11:17:23Z")

</div>

Hey guys, i started tinkering around with actionscript a few weeks back. Hence, i don’t really know the more complicated syntax. However, since i was learning programming (C, VB etc) a looong time back, i figured i’d be able to work out the underlying logic.

Problem: I can get a movie clip to play forward and backwards with two buttons. However, when i’m adding more buttons, which are supposed to get the movie clip to start playing from wherever it is, and to come and stop at x frame, i’m hitting a roadblock.

My stage currently has 3 buttons, with the following code:

BUTTON 1

```auto
on (release) {
	_global.newLink = 1;
	_global.buttonValue = "one";
}

```

BUTTON 2

```auto
on (release) {
	_global.newLink = 2;
	_global.buttonValue = "two";
}

```

BUTTON 3

```auto
on (release) {
	_global.newLink = 3;
	_global.buttonValue = "three";
}

```

My movie clip has the following script on it:

```auto
onClipEvent (load)
	{
	stop();
	_global.currentLink == 1;
	_global.newLink == 1;
	_global.buttonValue == "none";
	}

onClipEvent (enterFrame)
	{
	stop();
	
	if (_global.currentLink - _global.newLink < 0)
		{
		_global.dir = "fwd";
		}
	else if (_global.currentLink - _global.newLink > 0)
		{
		_global.dir = "bkw";
		}
	else
		{
		_global.dir = "stay";
		}
		
// FOR FORWARD MOTION
	if (_global.dir == "fwd")
		{
		if (_global.buttonValue == "two")
			{
			if (this._currentframe == 15)
				{
				stop();
				}
			else
				{
					this.nextFrame();
				}
			}
		else if (_global.buttonValue == "three")
			{
			if (this._currentframe == 24)
				{
				stop();
				}
			else
				{
					this.nextFrame();
				}
			}
		}

// FOR BACKWARD MOTION
	else if (_global.dir == "bkw")
		{
		if (_global.buttonValue == "two")
			{
			if (this._currentframe == 15)
				{
				stop();
				}
			else
				{
					this.prevFrame();
				}
			}
		else if (_global.buttonValue == "one")
			{
			if (this._currentframe == 1)
				{
				stop();
				}
			else
				{
					this.prevFrame();
				}
			}
		}
	else if (_global.dir == "stay")
		{
		stop();
		}
	}

```

Where am i screwing up?

---

<div class="post-metadata">

**Author:** ![bottleHeD](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bottleHeD](https://forum.kirupa.com/u/bottleHeD)\
**Post date:** [June 4, 2008, 11:27am UTC](https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237/2 "2008-06-04T11:27:27Z")

</div>

Sorry, forgot to attach the file, if anyone needed it.

---

<div class="post-metadata">

**Author:** ![bottleHeD](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bottleHeD](https://forum.kirupa.com/u/bottleHeD)\
**Post date:** [June 5, 2008, 5:54am UTC](https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237/3 "2008-06-05T05:54:38Z")

</div>

Hey, i fixed part of the mistake.

Changed this code:

```auto
onClipEvent (load)
	{
	stop();
	_global.currentLink == 1;
	_global.newLink == 1;
	_global.buttonValue == "none";
	}

```

to this:

```auto
onClipEvent (load)
	{
	stop();
	_global.currentLink = 1;
	_global.newLink = 1;
	_global.buttonValue = "none";
	}

```

Now the movie clip plays in one direction, atleast…

---

<div class="post-metadata">

**Author:** ![bottleHeD](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bottleHeD](https://forum.kirupa.com/u/bottleHeD)\
**Post date:** [June 5, 2008, 6:10am UTC](https://forum.kirupa.com/t/controlling-a-movie-clip-playing-forward-backward-with-multiple-buttons/262237/4 "2008-06-05T06:10:26Z")

</div>

It’s done!

I just had to add the following code inside the movie clip, on it’s timeline:

FRAME1

```auto
_global.currentLink = 1;

```

FRAME15

```auto
_global.currentLink = 2;

```

FRAME24

```auto
_global.currentLink = 3;

```

I’m attaching the file, if you guys wanna go through it and reuse the code…

Here’s the swf for a quick view:

[http://img515.imageshack.us/my.php?image=reversemoviescriptiy8.swf](http://img515.imageshack.us/my.php?image=reversemoviescriptiy8.swf)
