# Forward and backward

**URL:** <https://forum.kirupa.com/t/forward-and-backward/10207>\
**Category:** Uncategorized\
**Created:** [December 27, 2002, 1:01am UTC](https://forum.kirupa.com/t/forward-and-backward/10207 "2002-12-27T01:01:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kode](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kode](https://forum.kirupa.com/u/kode)\
**Post date:** [December 27, 2002, 1:01am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/1 "2002-12-27T01:01:48Z")

</div>

```php
onClipEvent (enterFrame) {
	if (this._currentframe == 1) playMe = true;
	if (this._currentframe == this._totalframes) playMe = false;
	if (playMe == true) this.nextFrame();
	if (playMe == false) this.prevFrame();
}

```

[SIZE=1] **PS:** I’ve seen this asked a few times in some forums… I thought I should share my way.[/size]

---

<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:** [December 27, 2002, 5:17am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/2 "2002-12-27T05:17:20Z")

</div>

Well in mx instead of making a whole new empty movie clip you can just put it on a frame like this…

```auto
_root.onEnterFrame = function() {
	if (this._currentframe == 1) {
		playMe = true;
	}
	if (this._currentframe == this._totalframes) {
		playMe = false;
	}
	if (playMe == true) {
		this.nextFrame();
	}
	if (playMe == false) {
		this.prevFrame();
	}
};

```

If ya wanted.

Very nice and simple code though.

---

<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:** [December 27, 2002, 5:26am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/3 "2002-12-27T05:26:17Z")

</div>

Of course, if you want to get all obfuscated and stuff, you can do this…

```auto
_root.onEnterFrame = function() {
	this._currentframe == 1 ? playMe=true : null;
	this._currentframe == this._totalframes ? playMe=false : null;
	playMe == true ? this.nextFrame() : this.prevFrame();
};

```

---

<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:** [December 27, 2002, 7:49am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/4 "2002-12-27T07:49:08Z")

</div>

Wow, I managed to condense it even more… obfuscating is FUN!!!

:: ok ok, I am just really bored right now, what do you expect at 3am ::

```auto
_root.onEnterFrame = function() {
	_currentframe == 1 ? playMe=true : _currentframe == _totalframes ? playMe=false : null;
	playMe ? nextFrame() : prevFrame();
};

```

---

<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:** [December 27, 2002, 8:04am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/5 "2002-12-27T08:04:24Z")

</div>

Hey I never said obfuscated was better, I just said I was bored 😉

LOL, I needed something to do and for some reason, I had flash opened and the original code inside and I started messing with it.

And yes, you are allowed to do \_root.onEnterFrame, I have seen it many places and used it many times myself. And I tested my code, it works.

And yes, it isn’t always best, because it gets all jumbled and confusing, so it is unreadable by the viewer and harder to process by the computer (I believe that is the way it goes).

Although obfuscated code does run slower depending on what you are doing, in this case it seems to run just the same (I think).

Some nice info here: [http://www.bit-101.com/forum/viewtopic.php?t=1051](http://www.bit-101.com/forum/viewtopic.php?t=1051) // pom 🙂

---

<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:** [December 27, 2002, 8:20am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/6 "2002-12-27T08:20:11Z")

</div>

Wow, if using show streaming in the preview can help you determine how long it takes to work (by saying how long it takes to load), then my code is actually quicker.

Didn’t expect that one.

---

<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:** [December 28, 2002, 2:39am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/7 "2002-12-28T02:39:46Z")

</div>

onClipEvent (enterFrame) {  
gotoAndStop(\_currentframe+dir);  
}

if dir (short for direction) is 1, it plays forward. 0, is stop and -1 is backward. 2 is twice the speed, -2 is twice the speed backwards. 3 is three times the speed… etc. You dont need to check for 1 or total frames because it will just cap off there anyway.

---

<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:** [December 28, 2002, 3:35am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/8 "2002-12-28T03:35:51Z")

</div>

Yeah, but that only plays in one direction senocular.

The code we are messing with plays forwards, and once it gets to the end, it plays the movie backwards, then forwards, then backwards, etc.

---

<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:** [December 28, 2002, 3:39am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/9 "2002-12-28T03:39:54Z")

</div>

just a simple version :\

---

<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:** [December 28, 2002, 3:43am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/10 "2002-12-28T03:43:50Z")

</div>

Yeah, but to make it go backwards then forwards again you will have to check for last and first frames :-\

---

<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:** [December 28, 2002, 3:58am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/11 "2002-12-28T03:58:15Z")

</div>

fine

```auto

gotoAndStop(_currentframe + (dir = (_currentframe == _totalframes) ? -Math.abs(dir) : (_currentframe == 1) ? Math.abs(dir) : dir));

```

---

<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:** [December 28, 2002, 4:14am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/12 "2002-12-28T04:14:49Z")

</div>

Test it, when it gets to the end it flicks back and forth rapidly 😉

---

<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:** [December 28, 2002, 4:32am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/13 "2002-12-28T04:32:54Z")

</div>

I did, works fine for me

---

<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:** [December 28, 2002, 4:33am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/14 "2002-12-28T04:33:53Z")

</div>

boy thats confusing!! can’t you programmers keep it simple :beam: 😛

---

<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:** [December 28, 2002, 4:35am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/15 "2002-12-28T04:35:51Z")

</div>

Interesting, That code in the .zip file is exactly the same, but when I use the code you put in your post, it doesn’t work.

Hmmmmm… odd. Oh well.

Anyone else got some interpretations of this code? I want to see how far we can take this :beam:

---

<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:** [December 28, 2002, 4:42am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/16 "2002-12-28T04:42:08Z")

</div>

yay Im not dumb afterall!

---

<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:** [December 28, 2002, 4:42am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/17 "2002-12-28T04:42:56Z")

</div>

Never said ya were 🙂 That code is very nice. I just wasn’t sure if you tested it because it wasn’t working on this end.

---

<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:** [December 28, 2002, 6:48am UTC](https://forum.kirupa.com/t/forward-and-backward/10207/18 "2002-12-28T06:48:22Z")

</div>

7000!! you can’t be stopped huh? 😛 😛

---

<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:** [December 28, 2002, 3:06pm UTC](https://forum.kirupa.com/t/forward-and-backward/10207/19 "2002-12-28T15:06:30Z")

</div>

> 

7005 (44.20 posts per day)

lol

how do you have time to code with all the time you spend in the forum? 😃

---

<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:** [January 15, 2003, 6:32pm UTC](https://forum.kirupa.com/t/forward-and-backward/10207/20 "2003-01-15T18:32:52Z")

</div>

now what if you wanted to have this action be triggered by a button? do I just make a action for the button?

[Next page](https://forum.kirupa.com/t/forward-and-backward/10207.md?page=2)
