Go Premium for a chance to win a PS4. Enter to Win


Center image when loadMovie to _root.stage

Posted on 2006-06-25
Medium Priority
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
1 Comment
LVL 12

Accepted Solution

Proactivation earned 2000 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

Technology Partners: 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

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,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

885 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