views:

22

answers:

1

I want to have something like a big still image that you can move by clicking buttons—with a "bouncing" effect. Buttons that moves to an specific position are fine, although additional buttons that allow you to move it freely within a certain restriction is even better.

I have an script for it in Actionscript 1.0 I found somewhere eons ago, yet I don't know how to update it for 3.0 (nor if there's a tutorial that explain any similar effect).

The script for the movable MovieClip:

onClipEvent (load) {
    moving = 0;
    x = 0;
    rebote = 0;
    section_actual = 1;
    section_new = 1;
    friction = 0.9;
}
onClipEvent (enterFrame) {
    if (moving == 1)
    {
        if (cambio == 1)
        {
            if (section_actual-section_new<0)
            {
                accel = -2;
            }
            else
            {
                accel = 2;
            }
        }
        cambio = 0;
        section_actual = section_new;
        if (accel == -2)
        {
            if (_x+xvel<=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
        if (accel == 2)
        {
            if (_x+xvel>=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
    }
}

The script for one button:

on (release) {
    tellTarget ("../")
    {
        moving = 1;
        x = -335;
        rebote = 0;
        section_new = 2;
        cambio = 1;
    }
}

Unrelated to the problem but still a need, I need to update the function of a button:

on (release) {
    _root.gotoAndStop("TT");
}
+2  A: 

There are entire library packages that can handle the entire animation chain with a single line of code.

Tweener

TweenLite

Tegeril