Solved

Center image when loadMovie to _root.stage

Posted on 2006-06-25
1
459 Views
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;
   });
};
i=0;
moviesToLoad.randomize();
ID = setInterval(loadRandomMovie, 20000);
function loadRandomMovie()
{
   i++;
   if (i >= moviesToLoad.length) i = 0;
  loadMovie("biblePicQuote/"+moviesToLoad[i] ,_root.stage);       }
loadRandomMovie();
0
Comment
Question by:gogetsome
[X]
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

by:
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;
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

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