# Make loading pic load in centre

**URL:** https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443
**Category:** Uncategorized
**Created:** [June 26, 2008, 6:13am UTC](https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443 "2008-06-26T06:13:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vineet](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vineet](https://forum.kirupa.com/u/vineet)
#### Post date: [June 26, 2008, 6:13am UTC](https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443/1 "2008-06-26T06:13:49Z")

</div>

hi everyone

i have seen this script mentioned on the below url

[http://www.kirupa.com/developer/actionscript/moviecliploader2.htm](http://www.kirupa.com/developer/actionscript/moviecliploader2.htm)

i want to know how can i centre the position of the image that we load. all these three external images when load are loaded from left top corner.

i mean if i resize the images to less width and height they load from top left corner. i want them to load in the centre.

fla is attached

vineet

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [June 26, 2008, 8:12am UTC](https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443/2 "2008-06-26T08:12:02Z")

</div>

search “stringy” he posted an fla recently with this code in I believe

---

<div class="post-metadata">

### Author: ![prg9](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@prg9](https://forum.kirupa.com/u/prg9)
#### Post date: [June 26, 2008, 2:12pm UTC](https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443/3 "2008-06-26T14:12:31Z")

</div>

> [@vineet;2349394](#):
>
> i want to know how can i centre the position of the image that we load. all these three external images when load are loaded from left top corner.

Hi vineet, welcome to Kirupa!

Use 2 containers (ie: container & subContainer). Below is an example, replace your code with this modified code (same code just a few chnages for centering):

```auto
MovieClip.prototype.fadeIn = function() {
	this.onEnterFrame = function() {
		if (this._alpha < 100) {
			this._alpha += 10;
		} else {
			delete this.onEnterFrame;
		}
	};
};
bar._visible = false;
border._visible = false;
//
this.createEmptyMovieClip("container", this.getNextHighestDepth()); // ** Added
container.createEmptyMovieClip("subContainer", this.getNextHighestDepth()); // ** Added
container._x = Stage.width / 2; // ** Added
container._y = Stage.height / 2; // ** Added
//
my_mc = new MovieClipLoader();
preload = new Object();
my_mc.addListener(preload);
preload.onLoadStart = function(targetMC) {
	container._alpha = 0;
	bar._visible = true;
	border._visible = true;
	pText._visible = true;
};
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {
	bar._width = (lBytes / tBytes) * 100;
	pText.text = "% " + Math.round((lBytes / tBytes) * 100);
};
preload.onLoadComplete = function(targetMC) {
	container.fadeIn();
	border._visible = false;
	bar._visible = false;
	dText._visible = false;
};
preload.onLoadInit = function(targetMC):Void { // ** Added
	targetMC._x = 0 - targetMC._width / 2;
	targetMC._y = 0 - targetMC._height / 2;
};
//default image
my_mc.loadClip("pic1.jpg", container.subContainer); // ** Added
//buttons
button1.onPress = function() {
	my_mc.loadClip("pic1.jpg", container.subContainer); // ** Added
};
button2.onPress = function() {
	my_mc.loadClip("pic2.jpg", container.subContainer); // ** Added
};
button3.onPress = function() {
	my_mc.loadClip("pic3.jpg", container.subContainer); // ** Added
};

```

Thats a basic example using the code you had, hope it gets your going in the right direction :thumb:

---

<div class="post-metadata">

### Author: ![vineet](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vineet](https://forum.kirupa.com/u/vineet)
#### Post date: [June 27, 2008, 8:35am UTC](https://forum.kirupa.com/t/make-loading-pic-load-in-centre/264443/4 "2008-06-27T08:35:49Z")

</div>

[QUOTE=prg9;2349578]Hi vineet, welcome to Kirupa!

Use 2 containers (ie: container & subContainer). Below is an example, replace your code with this modified code (same code just a few chnages for centering):

```auto
MovieClip.prototype.fadeIn = function() {
	this.onEnterFrame = function() {
		if (this._alpha < 100) {
			this._alpha += 10;
		} else {
			delete this.onEnterFrame;
		}
	};
};
bar._visible = false;
border._visible = false;
//
this.createEmptyMovieClip("container", this.getNextHighestDepth()); // ** Added
container.createEmptyMovieClip("subContainer", this.getNextHighestDepth()); // ** Added
container._x = Stage.width / 2; // ** Added
container._y = Stage.height / 2; // ** Added
//
my_mc = new MovieClipLoader();
preload = new Object();
my_mc.addListener(preload);
preload.onLoadStart = function(targetMC) {
	container._alpha = 0;
	bar._visible = true;
	border._visible = true;
	pText._visible = true;
};
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {
	bar._width = (lBytes / tBytes) * 100;
	pText.text = "% " + Math.round((lBytes / tBytes) * 100);
};
preload.onLoadComplete = function(targetMC) {
	container.fadeIn();
	border._visible = false;
	bar._visible = false;
	dText._visible = false;
};
preload.onLoadInit = function(targetMC):Void { // ** Added
	targetMC._x = 0 - targetMC._width / 2;
	targetMC._y = 0 - targetMC._height / 2;
};
//default image
my_mc.loadClip("pic1.jpg", container.subContainer); // ** Added
//buttons
button1.onPress = function() {
	my_mc.loadClip("pic1.jpg", container.subContainer); // ** Added
};
button2.onPress = function() {
	my_mc.loadClip("pic2.jpg", container.subContainer); // ** Added
};
button3.onPress = function() {
	my_mc.loadClip("pic3.jpg", container.subContainer); // ** Added
};

```

Thats a basic example using the code you had, hope it gets your going in the right direction :thumb:[/QUOTE]  
hi prg9

it was great to have your answer. it worked really as i wanted.

can u help with another thing based on same theory. this theory was for loading in levels.

now i have created the same thing but not in levels.  
i have created manually a bigmovieclip name “container” and inside it another movie “subcontainer”.  
and the script works fine with this theory also.  
but i want to know how can we make the external pic load in the centre of “container”.  
in our levels theory we have centre it according to stage.  
but now we dont have to centre it according to stage. its now according to container and subcontainer.

vineet
