Search code examples
flashactionscriptactionscript-2flash-cs5tween

Stop an animation in a child-movieclip from a parent once parent animation complete


I have a movieclip symbol of a sheep(symbol name: "sheep"). This animates across the screen. Inside the sheep movieclip there are tweens of its legs moving up and down. When the sheep stops moving I want the legs to also stop animating.

I've tried to access the legs from inside the function of the move:

function sheepMove6() {
    var sheepMoveX6:Tween = new Tween (inst_sheep, "_x", Strong.easeOut, 900, 850, 10, false);

    sheepMoveX6.onMotionFinished = function() {
        sheep.leg1MoveY.stop();
    }
}

I've also tried to detect the animation finishing from within the sheep movie clip:

_root.sheepMoveX6.onMotionFinished = function() {
    leg1MoveY.stop();
}

Neither of these seems to stop the legs from moving once the sheep has reached its destination. I'm using AS2.

--edit--

Not knowing how to target the child movieclip I've tried several different ways to access it, below, none have worked. Note: leg1MoveY is the name of the tween variable

_root.inst_sheep.inst_leg1.leg1MoveY.stop();
_root.inst_sheep.inst_leg1.stop();
_root.inst_sheep.stop();
_root.inst_sheep.inst_leg1.stop();
_root.inst_leg1.stop();
this.inst_sheep.inst_leg1.leg1MoveY.stop();
this.inst_sheep.inst_leg1.stop();
this.inst_sheep.stop();
this.inst_sheep.inst_leg1.stop();
this.inst_leg1.stop();

Solution

  • I can't quite tell the structure of your movie, but I suspect you're only declaring leg1MoveY inside a function in inst_leg1. If so, leg1MoveY can only be accessed from inside that function (its "scope" is limited to the function). Declare it outside of the function (I'm guessing at what leg1 does):

    var leg1MoveY:Tween;
    
    function legMove() {
        leg1MoveY = new Tween(... // Tween settings
    }
    

    Then the first line you tried should work:

    inst_sheep.inst_leg1.leg1MoveY.stop();
    

    There's an article here about scope in ActionScript 2 that might help.