Centering A Loaded Image/Movie

[LEFT]
[FONT=Arial][SIZE=2][COLOR=#0000ff]I am needing to load an external image (probably jpg) into a movie. I am using an empty movie clip, giving it an instance name and the code:

[/COLOR][/SIZE][/FONT]

instance1.loadMovie("image.jpg");

[/LEFT]
[LEFT] [/LEFT]
[LEFT][FONT=Arial][SIZE=2][COLOR=#0000ff]What I also need to do is be able to either place that image in a specific location on the stage or just center it. Any advice you can give me on that?

I am attempting to do something like this:[/COLOR][/SIZE][/FONT][/LEFT]
[LEFT] [/LEFT]
[LEFT][FONT=Arial][SIZE=2][COLOR=#0000ff]Use two movie clips. One is a holder that contains the second movie clip, which is where the image is actually being loaded. Then, I am using the following math:[/COLOR][/SIZE][/FONT][/LEFT]
[LEFT] [/LEFT]
[LEFT][/LEFT]

[LEFT]instance1.isntance2.x -  instance1._width/2[/LEFT]
 instance1.isntance2.y - instance1._width/2
 

[FONT=Arial][SIZE=2][COLOR=#0000ff]Does this look like it would work? Is there anyway I can set instance1 to have a width that is equal to the size of the main movie (1024 x 768)?[/COLOR][/SIZE][/FONT]

instance1._x = (Stage.width/2)-(this._width/2)
instance1._y = (Stage.height/2)-(this._height/2)

:slight_smile:

Thanks.

This will center the 0,0 point of the MC, right? Is there a way to reposition the image once it is loaded so that it is centered on the 0,0 point of the movie it is loaded into?

nope that will move that clip to the very center of the screen.

right, but it centers the 0,0 point of the clip, right?

nope. it centers the center of the clip, regardless of it’s dimensions

inctance1.loadMovie("image.jpg", "image1")
image1._x = 0;
image1._y = 0;
inctance1._x = Stage.width/2;
inctance1._y = Stage.height/2;

try that.

Thanks.

Odd. Every image i try and load streaks across the screen (even without the repositioning stuff).

ok, its not centering the way that I want it to. Here is a screenshot of the swf playing, with the actionscript I am using to load the image also visible.

http://www.jeremyflint.com/dev/screenshot.png

Here is the actionscript for reference:

image1.loadMovie("logo/image.jpg")
image1._x = (Stage.width/2)-(this._width/2)
image1._y = (Stage.height/2)-(this._height/2)

Thanks!

*bump

You’ll have to wait till the picture is loaded…

function loadPicture(clip) {
	image1.loadMovie(clip);
	var temp = this.createEmptyMovieClip("temp", 8899);
	temp.onEnterFrame = function() {
		if (image1._width) {
			image1._x = Stage.width/2-image1._width/2;
			image1._y = Stage.height/2-image1._height/2;
			delete this.onEnterFrame;
		}
	};
}
loadPicture("logo/image.jpg");

scotty(-:

Scotty = Actionscript Wizard