Abandoned
Abandoned

Reputation: 1

How to check if a movieclip has stopped rotating/spinning

I have a script where I press a button called spin_btnand once it is released it spins a wheel. Here is the AS for spin_btn:

spin_btn.onRelease = function()
{
    speed = randomRange(25, 900);
    spinning = true;

    if (spinning)
    {
    spin_btn._visible = false;
    }

};

Here is the AS that makes the wheel spin:

_root.onEnterFrame = function()
{
    spinning = true;
    if (spinning)
    {
        spinner_bg.spinner_wheel._rotation += speed;
        speed = speed * drag;

        if (Math.pow(speed, 2) < .0001)
        {
            speed = 0;
        }
    }
};

This is what I have tried inside the spin_btn function:

spin_btn.onRelease = function()
{
    speed = randomRange(25, 900);
    spinning = true;
    if (spinning)
    {
        spin_btn._visible = false;
    }
    else if (!spinning)
    {
        gotoAndStop(2);
    }
};

However once the wheel stops spinning, it doesn't go to frame 2 and i'm not too sure why. If anyone could help me out, then that would be great. Thank you.

Upvotes: 0

Views: 39

Answers (1)

weew
weew

Reputation: 363

If you want to move frame as soon as the wheel stops, you need to put the gotoAndStop(2); where you're currently setting the speed to 0

if (Math.pow(speed, 2) < .0001)
{
    speed = 0;
    gotoAndStop(2);
}

Also look at what your spinning variable is doing. You're setting it to true on the button release, but you're also setting it to true in onEnterFrame and you're not setting it to false anywhere so it doesn't really do anything at all. Currently you are controlling the wheel purely by setting the speed variable since spinning is always true

Upvotes: 1

Related Questions