Keith
Keith

Reputation: 45

click MC1 and wait till MC2 hits a certain frame

I have MC1 that when clicked i would like it to wait so it starts playing when MC2 hits frame 50 or 100. both have their own separate timeline. Any Help?

Upvotes: 1

Views: 99

Answers (2)

mfa
mfa

Reputation: 5087

addFrameScript will let you add and remove code to/from a movieclip frame.

function onMc1Click(e:MouseEvent):void
{
  //targetFrame:int = 50  declared in class..
  mc2instance.addFrameScript(targetFrame, mc2TargetFrameReached);
  mc2instance.play();
}

function mc2TargetFrameReached():void
{
  //call with null function value to remove 
  mc2instance.addFrameScript(targetFrame,null);

  //do other stuff
}

Upvotes: 3

GeorgeCross
GeorgeCross

Reputation: 359

mc1.addEventListener(MouseEvent.CLICK, onMc1Click);

function onMc1Click(e:MouseEvent):void
{
  mc2.addEventListener(Event.ENTER_FRAME, onFrameMc2);
  mc2.play();
}

function onFrameMc2(e:Event):void
{
  if(mc2.currentFrame == 50 || mc2.currentFrame == 100)
  {
    mc2.removeEventListener(Event.ENTER_FRAME, onFrameMc2);
    mc1.play();
  }
}

Upvotes: 1

Related Questions