Solved

Center image when loadMovie to _root.stage

Posted on 2006-06-25
1
457 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.

803 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