PDA

View Full Version : forward and backward



kode
December 26th, 2002, 09:01 PM
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();
}
PS: I've seen this asked a few times in some forums... I thought I should share my way.

lostinbeta
December 27th, 2002, 01:17 AM
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.

lostinbeta
December 27th, 2002, 01:26 AM
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();
};

lostinbeta
December 27th, 2002, 03:49 AM
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();
};

lostinbeta
December 27th, 2002, 04:04 AM
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 // pom :)

lostinbeta
December 27th, 2002, 04:20 AM
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.

senocular
December 27th, 2002, 10:39 PM
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.

lostinbeta
December 27th, 2002, 11:35 PM
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.

senocular
December 27th, 2002, 11:39 PM
just a simple version :\

lostinbeta
December 27th, 2002, 11:43 PM
Yeah, but to make it go backwards then forwards again you will have to check for last and first frames :-\

senocular
December 27th, 2002, 11:58 PM
fine



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

lostinbeta
December 28th, 2002, 12:14 AM
Test it, when it gets to the end it flicks back and forth rapidly ;)

senocular
December 28th, 2002, 12:32 AM
I did, works fine for me

Makaveli
December 28th, 2002, 12:33 AM
boy thats confusing!! can't you programmers keep it simple :beam: :P

lostinbeta
December 28th, 2002, 12:35 AM
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:

senocular
December 28th, 2002, 12:42 AM
yay Im not dumb afterall!

lostinbeta
December 28th, 2002, 12:42 AM
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.

kode
December 28th, 2002, 02:48 AM
7000!! you can't be stopped huh? :P :P

senocular
December 28th, 2002, 11:06 AM
7005 (44.20 posts per day)

lol

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

ckmoon17
January 15th, 2003, 02:32 PM
now what if you wanted to have this action be triggered by a button? do I just make a action for the button?

senocular
January 15th, 2003, 02:44 PM
look back one page, download the zip in the 4th post (on that page)

Arabonradar
January 15th, 2003, 03:26 PM
how would u make it just go backwords on like a mouseover?

ckmoon17
January 15th, 2003, 04:12 PM
yes like a mouseover. It's a motion tween with mutiple keyframes..I want with button that when touched to either go on to the next frame or if the frame is passed a certain number then go backwards to a specfic keyframe.

I'm really having a hard time with this because I'm not sure how to write the If statements for determaining which way to go by what frame it's on.....or the backwards scripts

I saw this site that gave me an idea for my portfolio I'm doing..It will help explain ...it's
www.sofake.com

lostinbeta
January 15th, 2003, 04:14 PM
I am not sure I understand exactly what you want.


So I am going to assume you want it to stop before it reverses, then have the clip when rolled over to play in reverse. I don't know what you want it to do after that, but maybe this is a shove in the right direction...


_root.onEnterFrame = function() {
if (this._currentframe == 1) {
playMe = true;
}
if (this._currentframe != this._totalframes) {
delete _root.ball.onRollOver;
} else {
_root.stop();
_root.ball.onRollOver = function() {
playMe = false;
};
}
if (playMe == true) {
this.nextFrame();
}
if (playMe == false) {
this.prevFrame();
}
};

My method involves that code be put on the first frame of your timeline. And the tween must be done to a movie clip with the instance name "ball" (no quotes, and not IN the movie clip, but TO the movie clip).

ckmoon17
January 15th, 2003, 04:30 PM
thanks lostinbeta I think that will help basicly what i'm trying to do is explain in my last post for a visual go to www.sofake.com and press buttons out of order and you'll understand

lostinbeta
January 15th, 2003, 04:36 PM
<B>ckmoon:</B> I am pretty sure sofake uses the _xscale and _yscale properties with actionscript to make their site... not tweens. But ya never know.


<B>Arabonradar:</B>If you want the movie to start off stopped, but play when rolled over, then stop before the reverse. Then when you roll over the clip again it will play the reverse (confusing eh?) you can do something like this (please keep in mind that there are probably a billion and a half ways to optimize this, I just did this real quick)....

Follow the same rules as my last post. But use this code..

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

This... stops your movie on frame 1 with the stop(); action at the end. Then the _root.ball.onRollOver in the very beginning awaits the onRollOver of the clip on the main timeline with the instance name "ball" (no quotes) before it assigns the variable playMe to be true. The if statement at the end that says if playMe is true then play the nextframe (which when repeated acts like a play button). Then the the if statments check if it is on the last frame of the animation, and if so it stops the timeline and assigns a new rollOver action for the movie clip. It assigns the variable playMe as false, which the last if statement says that if playMe is false then play the previous frame (which played repeated creates a playback type thing).

Arabonradar
January 15th, 2003, 06:49 PM
it is very much like the code, beta, but i want 2 buttons, 1 to play forward. 1 to play backwords on mouseover. like scrolling a motion tween

lostinbeta
January 15th, 2003, 06:55 PM
There is something like that in the 2nd page of this thread.


Senocular posted it, it is an attachment called swing.zip.

Arabonradar
January 15th, 2003, 07:09 PM
swing is what im looking for basically, but i dont want the clip to start forward then go the opposite direction, or start backwords and go the opposite direction. i just want it to go one direction only for each button

lostinbeta
January 15th, 2003, 07:16 PM
Create a movieclip with the instance name ball.

INSIDE that movie clip create your tween.

Have a stop() action on Frame 1.


On the main stage create 2 movie clips, one as the back buton and one as the forward button.

On the back button movie clip add these actions..

on (rollOver) {
this.onEnterFrame = function() {
_root.ball.prevFrame();
};
}
on (rollOut) {
delete this.onEnterFrame;
}

On the forward button movie clip add these actions...

on (rollOver) {
this.onEnterFrame = function() {
_root.ball.nextFrame();
};
}
on (rollOut) {
delete this.onEnterFrame;
}

Arabonradar
January 15th, 2003, 07:28 PM
WOOHOO! Thanks so much!

lostinbeta
January 15th, 2003, 07:30 PM
No problem.


Where did h88s post go though?

He posted right before me with some nice code, then he deleted it :-\

h88
January 15th, 2003, 07:32 PM
Thought it was an off topic when i was checking your codes,

MovieClip.prototype.backward = function() {
this.gotoAndStop(this._totalframes);
this.onEnterFrame = function() {
this.gotoAndStop(this._currentframe-1);
};
};

(** Usage: **)

myClip.backward();

lostinbeta
January 15th, 2003, 07:36 PM
This whole thread is about backwards playing... there are about 4 different methods of doing it now in this one thread ;)

jcs
February 17th, 2003, 11:23 AM
There's a navigation effect I see a lot in which you click on a button and it plays some MC. When you click on one of the other buttons, the current MC reverses out and the MC for the other button animates in, and so forth.

A good example is the navigation in http://fontsforflash.com

I'm sure the MCs are playing in an emptyMovieClip, but how do you code the buttons to reverse the current MC and play the new one?

Any thoughts are appreciated.

JCS

lostinbeta
February 17th, 2003, 04:10 PM
I believe that is a different method that this one. Probably main tweens that are triggered to play through variables of some sort.

kode
February 17th, 2003, 08:29 PM
Here's an example. And now I gotta go. =)

lostinbeta
February 17th, 2003, 11:42 PM
nice clean code kax :)

kode
February 17th, 2003, 11:50 PM
For something that took 5 minutes it's not that bad... ;)

Seriously, coming from one of the few people I actually like his work... it's really appreciated. Thanks, lost. =)

lostinbeta
February 18th, 2003, 12:00 AM
Well I learn a lot from you, and I appreciate that. This menu thing is one thing I learned from you :)

kode
February 18th, 2003, 12:48 AM
That's why I love this forum. :)

You never know what you'll learn each day .. there's always something new. =)

pom
February 18th, 2003, 06:30 AM
All right, I'll put this in the BOK, after I've cleaned the SPAM... :bad:

senocular
February 18th, 2003, 06:57 AM
just thought Id throw another version of the pixel menu out which I made before kax posted (beating me to it ;))

What you can do is just takes kax's file and throw this code in it (I also stole kax's array - I just had the mc actions stringed out equaling each other :beam: )

Now this versions shorter but the onEnterFrame events are constant. Kax went to the trouble of deleting them when not needed and I commend that :) - this is just another take on whats doing the same thing.



inx = 40;
outx = 100;
ease = 3;
clips = [menu1, menu2, menu3, menu4, menu5, menu6];
selected = null;

clicked = function(){
selected.targ = inx;
(selected = this).targ = outx;
}
easeTo = function(){
this._x += (this.targ-this._x)/ease;
}

for (i=0; i< clips.length; i++){
clips[i].onRelease = clicked;
clips[i].onEnterFrame = easeTo;
clips[i].targ = inx;
}

jcs
February 18th, 2003, 10:36 AM
I know I'm not supposed to reply in BOK, but THANKS! Great help, guys. I've learned a lot from these forums and I appreciate your enthusiasm and expertise in tackling questions like this.

Cheers,
jcs

vik
June 12th, 2004, 02:03 PM
Hi !!! this is great stuff.

say i want to be able to play all the frames on a movie clip and then reverse and stop at frame 1 how could i do this???.

like ball.onRollOver = function () {
//something here
}

Tanx

alijumcepa
December 19th, 2004, 09:03 PM
Suppose, we change frames to loaded SWFs and store references to XML file. Then we make a bunch of arrays or just one and every time we click on button or link, our system listen for that and put reference inn array, the only two buttons do their job(BACK and FORWARD). We need only 1 main SWF like container and then just calling SWFs with buttons or links in text fields via asfunction. Is there any traps? Tell me...

spitfly
July 7th, 2005, 04:26 AM
what if i want the rollover action to play a movie forward and let it stop at a certain frame and on rollout it will play backward ?