How to prevent external translation of a movieclip object on stage in AS3?

Posted by Aaron H. on Stack Overflow See other posts from Stack Overflow or by Aaron H.
Published on 2010-03-19T00:17:42Z Indexed on 2010/03/19 1:21 UTC
Read the original article Hit count: 315

I have a MovieClip object, which is exported for actionscript (AS3) in an .swc file.

When I place an instance of the clip on the stage without any modifications, it appears in the upper left corner, about half off stage (i.e. only the lower right quadrant of the object is visible). I understand that this is because the clip has a registration point which is not the upper left corner.

If you call getBounds() on the movieclip you can get the bounds of the clip (presumably from the "point" that it's aligned on) which looks something like (left: -303, top: -100, right: 303, bottom: 100), you can subtract the left and top values from the clip x and y:

clip.x -= bounds.left;
clip.y -= bounds.top;

This seems to properly align the clip fully on stage with the top left of the clip squarely in the corner of the stage.

But! Following that logic doesn't seem to work when aligning it on the center of the stage!

clip.x = (stage.stageWidth / 2);
etc...

This creates the crazy parallel universe where the clip is now down in the lower right corner of the stage.

The only clue I have is that looking at:

clip.transform.matrix

and

clip.transform.concatenatedMatrix
  • matrix has a tx value of 748 (half of stage height) ty value of 426 (Half of stage height)

  • concatenatedMatrix has a tx value of 1699.5 and ty value of 967.75

That's also obviously where the movieclip is getting positioned, but why? Where is this additional translation coming from?

© Stack Overflow or respective owner

Related posts about as3

Related posts about movieclip