Center image when loadMovie to _root.stage

Posted on 2006-06-25
Last Modified: 2012-05-05
Hello, I have a small function which loads a graphic into a movie clip and I need help when the graphic is loaded to be centered in the movie. How can this be accomplished? Can my code be modified?

Here is my code:

moviesToLoad = new Array("001.jpg", "002.jpg", "003.jpg", "004.jpg");
Array.prototype.randomize = function()
   return this.sort(function (a, b)
       return (Math.floor(Math.random() * 2) == 0) ? 1 : -1;
ID = setInterval(loadRandomMovie, 20000);
function loadRandomMovie()
   if (i >= moviesToLoad.length) i = 0;
  loadMovie("biblePicQuote/"+moviesToLoad[i] ,_root.stage);       }
Question by:gogetsome
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 12

Accepted Solution

Proactivation earned 500 total points
ID: 16983181
I haven't tested it, but something like this should do what you need:

moviesToLoad = new Array("001.jpg", "002.jpg", "003.jpg", "004.jpg");
Array.prototype.randomize = function() {
    return this.sort(function (a, b) {
        return (Math.floor(Math.random() * 2) == 0) ? 1 : -1;
i = 0;
ID = setInterval(loadRandomMovie, 20000);
var loadListener:Object = new Object();
loadListener.onLoadInit = function(target_mc:MovieClip):Void  {
    target_mc._x = (Stage.width = target_mc._width) / 2;
    target_mc._y = (Stage.height = target_mc._height) / 2;
function loadRandomMovie() {
    i += 1;
    i %= moviesToLoad.length;
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mcLoader.loadClip("biblePicQuote/" + moviesToLoad[i], mc);

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question