PDA

View Full Version : Center MC on stage!



m90
February 9th, 2009, 05:57 AM
Hello!

I have a MC on stage that I dynamically add and remove elements to and from. Since its dimensions vary subject to those changes I's like to "pin-point" it to the center of my (800x600) stage. I thought it would be agood idea to get the dimensions of the MC (it's called container) and set its x and y accordingly, but somehow it won't work as I got the feeling the registration is somewhere else (and I don't get the logic behind where it is).

The code I am using at the moment is the following


var dimensions:Rectangle = container.getBounds(stage);
container.x = 400 - dimensions.width/2;
container.y = 300 - dimensions.height/2;
Thanks alot in advance!

smallDot
February 9th, 2009, 06:25 AM
try


mc.x = stage.stageWidth / 2
mc.y = stage.stageHeight / 2

m90
February 9th, 2009, 06:31 AM
Thanks! Unfortunately it is not working but it led me to the fact that the registration of the container MC seems to be locked to the lowest Child in the container.

I have read about this already, but can I somehow the registration of the MC to its actual center?

Thanks!

Dawn0fDusk
February 9th, 2009, 11:00 AM
Yeah, just open up the MovieClip (Double click or w/e) and move it into the middle of the crosshair, then run it.