views:

23

answers:

1

Hello,

I'm dynamically creating an empty movieclip inside another movieclip to load an image into it. How could i make sure that this image is always centred in the movieclip?

Also, if i have a attached movieclip named E.G. 1M how do i find out the x and y position to make it appear next to each other?

+1  A: 

To center an object in a container, you need to do the following

 Pseudo Code 
 object.x = ( container.width - object.width )/2;
 object.y = ( container.height - object.height )/2;

since you need all these dimensions to be set before centering an object, you can only apply the above after your image has loaded.

You would typically add that code in your complete event listener. If your image is loaded inside a MovieClip and you want that MovieClip to be centered within its container, you can apply the same formula, only you'll apply it to the image container ( object ) & the container parent ( container ).

PatrickS