PDA

View Full Version : Nice Rollover with no excess onEnterFrames



matthewjumps
August 17th, 2006, 09:35 PM
heres a rollover technique that tweens in and out smoothly, say if it gets 5 frames into the tween in, and then u roll out well it play backwards straight away. oh and theres no constantly running onENterframes wasting CPU....

not new but kinda handy i think

EDIT: God how do i re-attach this thing??!?!?!?!

Templarian
August 17th, 2006, 09:59 PM
Something doesnt work.

matthewjumps
August 17th, 2006, 10:14 PM
Oh? dammit what did i do? Also why cant i attach a swf?

EDIT: ill attach it again

cryo.burned
August 17th, 2006, 10:20 PM
.swf are no longer an acepted format

theHollow
August 17th, 2006, 11:43 PM
The person who hacked the site used an attached swf to do it. You need to link to the swf on an external site.

B L U E
August 18th, 2006, 12:15 AM
just post the code here?

heres a rollover technique that tweens in and out smoothly, say if it gets 5 frames into the tween in, and then u roll out well it play backwards straight away. oh and theres no constantly running onENterframes wasting CPU....

Anogar
August 18th, 2006, 12:26 AM
Post the code. Its just a button examle, how much scene setup can you possibly need?

matthewjumps
August 18th, 2006, 01:12 AM
not much.


on (rollOver) {
this.button.useHandCursor = false;
overVar = 1;
//
this.onEnterFrame = function() {
if (overVar == 1 && this._currentframe<15) {
this.gotoAndStop(this._currentframe+1);
} else if (overVar == 0 && this._currentframe>1) {
this.gotoAndStop(this._currentframe-1);
} else if (overVar == 0 && this._currentframe == 1) {
delete this.onEnterFrame;
}
};
}
on (rollOut) {
overVar = 0;
}

thats the gist of it

http://www.freefileupload.net/file.php?file=files/180806/1155877868/Rollovers.swf
http://www.freefileupload.net/file.php?file=files/180806/1155877821/Rollovers.fla

andrewfitz
August 18th, 2006, 01:59 AM
It's nice, but what's the point of the AS code, if it's just frame tweened?

Icy Penguin
August 18th, 2006, 02:00 AM
Is it supposed to just say START four times and do nothing else? :lol:

I tried making something like this before. But I suck at Flash. So it didn't quite work very well.

Looking forward to seeing it work, I will definitely use it!:D

Thanks!

theHollow
August 18th, 2006, 02:07 AM
Very nice. I've altered your code a little bit and got it to work as a function.

matthewjumps
August 18th, 2006, 03:11 AM
@theHollow - thanks i like it too :) simple but handy. that function version is good too. theres probably an even cooler way to implement it by extending some class or another....

@Icy Penguin - it does work. roll over one of the START buttons.

@FatalDisruption - :pa: um it doesnt just use tweens. it uses AS to rewind/play a tween when u roll over/out. so if you sweep the cursor across the row of buttons then you wont get an annoying wave of tweens, the buttons will start tweening out as soon as you roll out. so its nice and smooth.

alkalinetb
August 18th, 2006, 07:24 AM
Can you not use setInterval and do away with onEnterFrame completely?

digitaldivide
August 18th, 2006, 12:44 PM
I also like this very much. Is there a particular reason why the code overVar = 1; in the beginning only has got one "=" instead of two "=="? And the following code has got always two "=="? I've been running into this a lot of times and I still don't exactly know why this should be this way... Maybe a dum question, but it's better to ask than to not know it!

andrewfitz
August 18th, 2006, 01:36 PM
Well, I suppose I meant, in some off the wall fasion, could you acheive the same effect with 100% AS, maybe using the Tween class? Frame tweening isn't really portable. But like I said, I like it anyways.

Anogar
August 18th, 2006, 01:42 PM
Isn't this pretty much exactly the same thing as this Kirupa tutorial:

http://www.kirupa.com/developer/mx2004/button_effect.htm

...except with a delete onEnterFrame function and some slightly messier and less useful code?

:h:

mprzybylski
August 18th, 2006, 01:51 PM
Here is an even easier/better way of doing this (and a true way of not using onEnterFrame):


import mx.transitions.easing.*;
import mx.transitions.Tween;

box_mc.onRollOver = function():Void
{
var _tween:Tween = new Tween(this, "_xscale", Regular.easeOut, this._xscale, 200, .5, true);
};

box_mc.onRollOut = function():Void
{
var _tween:Tween = new Tween(this, "_xscale", Regular.easeOut, this._xscale, 100, .5, true);
};

the benefit of this is also that you can use different easing equations like elasticity and bounce.

although this is a useful class, i tend to use TweenExtended by square circle (www.sqcircle.com/downloads) because it allows you to tween multiple properties in one line.

however! i just made a new class called SuperTween last night that allows you to do all that TweenExtended does AND have a callback function with parameters. I'll release it here soon, just tyding it up a bit.

kapi187
August 18th, 2006, 01:56 PM
The person who hacked the site used an attached swf to do it. You need to link to the swf on an external site.
Don't mean to bring this back up if no one wants to talk about it... but... What happened? When was this?:ear:

B L U E
August 18th, 2006, 06:20 PM
Here is an even easier/better way of doing this (and a true way of not using onEnterFrame):


import mx.transitions.easing.*;
import mx.transitions.Tween;

box_mc.onRollOver = function():Void
{
var _tween:Tween = new Tween(this, "_xscale", Regular.easeOut, this._xscale, 200, .5, true);
};

box_mc.onRollOut = function():Void
{
var _tween:Tween = new Tween(this, "_xscale", Regular.easeOut, this._xscale, 100, .5, true);
};

the benefit of this is also that you can use different easing equations like elasticity and bounce.

although this is a useful class, i tend to use TweenExtended by square circle (www.sqcircle.com/downloads) because it allows you to tween multiple properties in one line.

however! i just made a new class called SuperTween last night that allows you to do all that TweenExtended does AND have a callback function with parameters. I'll release it here soon, just tyding it up a bit.The Tween class essentially is an onEnterFrame:) Good code though, I don't see the fuss about having a few OEF's.

Krilnon
August 18th, 2006, 11:49 PM
B L U E makes a good point. Having one or more onEnterFrame handlers is not some sort of doom formula for the performance of your movie. It's actually quite possible to have many of them and have a movie that is quite speedy. The reason that so many people warn others about onEnterFrame handlers is that there have been quite a few instances where people have forgotten to delete/nullify these handlers or have placed a processor-intensive script in the handler without realizing what a demanding task they are asking.

Using intervals isn't a magic cure that will fix everything, either. A processor-intensive script isn't going to suddenly become lightweight once it is moved over to an interval running at the same (or similar) rate as a movie's framerate. It's probably more likely that one would run into troubles clearing an interval than disabling the onEnterFrame handler, as interval IDs are more complicated to keep track of.

With that said, I don't mean to imply that letting handlers keep running after their use has disappeared is a good thing, I just think that the perception of onEnterFrame handlers as 'evil' is a bit silly.

matthewjumps
August 19th, 2006, 03:09 AM
Isn't this pretty much exactly the same thing as this Kirupa tutorial:

http://www.kirupa.com/developer/mx2004/button_effect.htm

...except with a delete onEnterFrame function and some slightly messier and less useful code?

:h:
actually id never seen that before. and my version is slightly better in the overall way, as you dont have tons of onEnterframes going on button mcs that havent even been rolled over. so if you want to think of it as a slight improvement thats fine by me (-:

i guess i/someone could redo it using the more logical code from that example but with the selective use of onEnterFrames to make a version that is the most efficient and doesnt waste CPU. maybe even update that example. cause having onEnterFrames running non-stop on lots of buttons when theyre unnessecary is certainly not good.

and why use an interval? i want to go forward or backwards one frame at the framerate of the movie. why worry about working out how many milliseconds is equivalent to 30 fps - onEnterframe is way more logical.

oh and i couldnt be stuffed making the tweens in AS. a one way motion tween suffices to get the point across :party:

mprzybylski
August 19th, 2006, 09:09 PM
The Tween class essentially is an onEnterFrame:) Good code though, I don't see the fuss about having a few OEF's.

you're absolutely right, it uses onEnterFrameBeacon. I just think it manages it better than doing it manually.

but yes, as lond as you do it manually and clear the onEnterFrame/interval, then you're fine. I just like to use whats already given to me and built into flash. i think using the Tween class is the cleanest way of doing it. one line of code handles the whole thing (unless you're tweening multiple properties, in which case you can use the TweenExtended class i talked about to do it in one line) :P

theHollow
August 20th, 2006, 07:45 AM
Don't mean to bring this back up if no one wants to talk about it... but... What happened? When was this?:ear:

Im not 100% sure, but here: kirupa.com/forum/showthread.php?t=227259 (http://www.kirupa.com/forum/showthread.php?t=227259)