Skip to main content
Venian
Inspiring
October 26, 2006
Question

how to center an image in a movie clip

  • October 26, 2006
  • 2 replies
  • 286 views
Hi

I have loaded an image at runtime into a movieclip (holder_mc) nested within another movieclip (image_mc) placed onto the stage. So I want to center the newly loaded image into the movieclip, because I load different images with diferrent sizes. So if the image is smaller than the movieclip I want it to be on the center of the movieclip.

Could some one help me?

Thnak you.
This topic has been closed for replies.

2 replies

Inspiring
October 26, 2006
kglad wrote:
> AFTER loading is complete (ie, use preloader code or the onLoadInit() method of
> the moviecliploader class), you can use:
>
>
>
> image_mc.holder_mc._x=.5*(image_mc._width-image_mc.holder_mc._width);
> image_mc.holder_mc._y=.5*(image_mc._height-image_mc.holder_mc._height);
>


The original poster didn't mention if they were using MovieClipLoader or
loadMovie(). I thought it worth mentioning that you need to use the
MovieClipLoader class because the onLoadInit() event handler won't be
available if you are using the loadMovie() method.

I would also Math.round() your values so the image lines up on full
pixels so there is no bitmap distortion.

James


--
James O'Reilly — Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design • Code • Train
kglad
Community Expert
Community Expert
October 26, 2006
AFTER loading is complete (ie, use preloader code or the onLoadInit() method of the moviecliploader class), you can use: