Center image when loadMovie to _root.stage

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;
   });
};
i=0;
moviesToLoad.randomize();
ID = setInterval(loadRandomMovie, 20000);
function loadRandomMovie()
{
   i++;
   if (i >= moviesToLoad.length) i = 0;
  loadMovie("biblePicQuote/"+moviesToLoad[i] ,_root.stage);       }
loadRandomMovie();
gogetsomeAsked:
Who is Participating?
 
ProactivationConnect With a Mentor Commented:
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;
moviesToLoad.randomize();
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();
    mcLoader.addListener(loadListener);
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mcLoader.loadClip("biblePicQuote/" + moviesToLoad[i], mc);
}
loadRandomMovie();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.