Forward and backward

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]

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

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

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

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

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 ::

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

Hey I never said obfuscated was better, I just said I was bored :wink:

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 // pom :slight_smile:

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.

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.

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.

just a simple version :\

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

fine


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

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

I did, works fine for me

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

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:

yay Im not dumb afterall!

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

7000!! you can’t be stopped huh? :stuck_out_tongue: :stuck_out_tongue:

7005 (44.20 posts per day)

lol

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

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