Search code examples
actionscript-3animationpositionmovieclip

Trace x,y of movieclip that is animated through timeline


I am trying to trace the position of a movieclip(that contains a simple timeline animation inside) so that I can attach another movieclip to be able to follow it.

How can I do that?

empty = the movieclip that contains timeline animation

mc = the movieclip I want to follow the "empty" movieclip

empty.addEventListener(Event.ENTER_FRAME, onMove);

function onMove(event:Event):void {
    var mc:MovieClip = new SmokeTween();
    mc.x = empty.x;
    mc.y = empty.y;
    mc.rotation = Math.round(Math.random() * 70);
    this.addChild(mc);
}

Actually I went into "empty" mc and and used this code and seems to work fine:

this.addEventListener ( Event.ENTER_FRAME, traceFrame );

function traceFrame ( e : Event ) : void
{
    if (e.target.currentFrame > 0){
        MovieClip(parent.parent).mc.x = e.target.x;
    }
}

Solution

  • Actually I went into "empty" mc and and used this code and seems to work fine:

    this.addEventListener ( Event.ENTER_FRAME, traceFrame );
    
    function traceFrame ( e : Event ) : void
    {
        if (e.target.currentFrame > 0){
            mc.x = e.target.x;
        }
    }