A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Rollover with Actionscript

  1. #1

    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!
    mikeparker

  2. #2
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    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

  3. #3
    the friendly canadian DaVulf's Avatar
    Join Date
    Feb 2004
    Location
    Singapore
    Posts
    2,017
    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.easeOutbutton_mc._xscale2002true);
            var 
    loTween_y = new mx.transitions.Tween(button_mc"_yscale"mx.transitions.easing.Bounce.easeOutbutton_mc._yscale2002true);

    }

    //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.easeOutbutton_mc._xscale1002true);
            var 
    loTween_y = new mx.transitions.Tween(button_mc"_yscale"mx.transitions.easing.Bounce.easeOutbutton_mc._yscale1002true);


    Hope that helps!

  4. #4
    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!
    mikeparker

  5. #5
    the friendly canadian DaVulf's Avatar
    Join Date
    Feb 2004
    Location
    Singapore
    Posts
    2,017
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center