Skip to main content
Inspiring
June 10, 2013
Question

Movie clip added by addChild won't start immediately.

  • June 10, 2013
  • 1 reply
  • 2186 views

Hello. I am using Flash CS6.

I added 2 frames long movieclip by addChild, but it plays 3 frames.

Main timeline has 10 frames and I wrote this AS on frame 5.

var test= new test_lib();

test.x = stage.stageWidth/2;

test.y =  stage.stageHeight/2;

Object(root).addChild(test);

but It starts to play one frame after added, so it starts to play not on frame 5,but on frame 6.

So it looks like playing  "frame 1","frame 1","frame 2".

I need to start the movieclip immediately after adding it(I need it to start on frame 5) by addChild.

What should I do?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 10, 2013

your explanation is not consistant with the default behavior of flash.

when you create your movieclip (the var test=new test_lib() line), test is at frame 1 and if that code is on your main timeline's frame 5, then test will be at frame 1 when your main timeline is at frame 5.

if there is no other code (ie, stops, gotos etc), test will be at its frame 2 when the main timeline is at frame 6.  to confirm, add a keyframe to test's 2nd frame and attach the following code to test's 2nd frame:

trace(this.currentFrame,this.parent.currentFrame);

Inspiring
June 10, 2013

I got 1,5 and 2,7. It seems 1 frame of test mc shows twice on frame 5 and 6.

kglad
Community Expert
Community Expert
June 11, 2013

http://fast-uploader.com/file/6926452337251/

sorry. try this and click the link at the bottom of the page.


ok.

it does start right away but it takes an extra clock cycle to play its 2nd frame.  from there both play one frame per clock cycle.

here's the result of using code to create and instance vs an instance added to the ide when the following is on the first 6 frames of the movieclip and both are created in the parent's first frame and fps is 10:

trace(this.name,this.currentFrame, MovieClip(this.parent).currentFrame, getTimer())

ide 1 1 3

coded 1 1 5

ide 2 2 110

ide 3 3 212

coded 2 3 212

ide 4 4 312

coded 3 4 312

ide 5 5 412

coded 4 5 412

ide 6 6 512

coded 5 6 512

coded 6 6 612