jeudi 31 décembre 2015

Play different animation on every other rollover?

I have a couple of buttons which have corresponding movieclips. Every movieclip has two different animations (first starts at frame 1, second on frame 20). I want the animations to play alternating on MOUSE.OVER

Now I am wondering how to do this with one function. Buttons are always named e.g thing and movieclips thing_mc.

I was thinking something like this:

var thing_bo:Boolean = false;

function over(e:MouseEvent)
{
    var mcName = e.currentTarget.name + "_mc";
    var yourContainer:DisplayObjectContainer = e.currentTarget.parent as DisplayObjectContainer;
    var mc = yourContainer.getChildByName( mcName );

    var boName = e.currentTarget.name + "_bo";

    if (!boName) {
        mc.gotoAndPlay(1);
        boName = true; 
    } else {
        mc.gotoAndPlay(20);
        boName = false; 
    }
}

How to I get this to work? Is there a simpler way?

Aucun commentaire:

Enregistrer un commentaire