-
Rollover with Actionscript
Hey everybody-
I was looking for an MX tutorial about using actionscript for a rollover effect. Here's what I'd like to do:
When the button is rolled over, the graphic begins to scale up and once it's rolled off, the graphic starts to scale back to it's original shape. I would also like the scaled item to have alittle bounce to it, or ease into and out of the scaling if possible
I know I can do a simple version with tweens, but I'd like to have it look smoother than that.
Any help on this topic would be appreciated
Thanks in advance!
-
Banned
Hi,
code:
bounce = function (targetMC) {
_root.onLoad = function() {
speed = 4;
friction = 0.85;
home = 100;
}
this.onEnterFrame = function() {
if (targetMC.hitTest(_root._xmouse, _root._ymouse)) {
target = 150;
} else {
target = 100;
}
dif = target-targetMC._xscale;
vel = (vel+(dif/speed))*friction;
targetMC._xscale = targetMC._yscale += vel;
if (target == 150 && Math.abs(dif)<.5) {
target = 100;
}
}
}
//Usage
bounce(myClip);
NTD
-
the friendly canadian
Also, since you were looking for a tutorial...
Here is a really cool effect in MX 2004. You can just modify your rollOver action to target the function.
PHP Code:
attachMovie("button", "button_mc", 99, {_x:325, _y:225});
button_mc._xscale = 100;
button_mc._yscale = 100;
stop();
button_mc.onRollOver = function() {
expandButton();
};
button_mc.onRollOut = function() {
contractButton();
};
//This function would expand the button to twice it's normal size.
function expandButton() {
var loTween_x = new mx.transitions.Tween(button_mc, "_xscale", mx.transitions.easing.Bounce.easeOut, button_mc._xscale, 200, 2, true);
var loTween_y = new mx.transitions.Tween(button_mc, "_yscale", mx.transitions.easing.Bounce.easeOut, button_mc._yscale, 200, 2, true);
}
//This brings the button down to it's original size.
function contractButton() {
var loTween_x = new mx.transitions.Tween(button_mc, "_xscale", mx.transitions.easing.Bounce.easeOut, button_mc._xscale, 100, 2, true);
var loTween_y = new mx.transitions.Tween(button_mc, "_yscale", mx.transitions.easing.Bounce.easeOut, button_mc._yscale, 100, 2, true);
}
Hope that helps!
-
Thanks to both of you for your help- I'm a bit of a newbie when it comes to AS. I've done the basic stuff, but this stuff seems to be over my head a bit.
I'll try it out and see what I can get working
Thanks again!
-
the friendly canadian
Don't worry about it. Took me a while to get that code through my head when I first started using it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|