Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

centering my jpeg inside a movie clip.

Status
Not open for further replies.

flashdunce

Technical User
Nov 30, 2006
9
0
0
US
Hi again Now that i have suuccessfully loaded my jpeg into the movieclip the jpeg seems to load in the corner of the movie clip. Is there a way to have the jpeg file centered inside the movie clip?
 
That's a little more difficult...

You need to use a second container clip nested inside the first one, and since you need the picture's dimensions, to center it, the picture has to be fully loaded before you can access it's width & height...

The following script will do it... Containers are dynamically created so you need nothing on stage...

Code:
stop();
// create this movie clip, and storing it as a variable container
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
// centralising it to stage
container._x = Stage.width / 2;
container._y = Stage.height / 2;
 
// create a second movie clip within container, this is to manipulate the _x and _y properties
var image:MovieClip = container.createEmptyMovieClip("image", container.getNextHighestDepth());
 
// create a movie clip loader for checking of loading progress
var mcLoader:MovieClipLoader = new MovieClipLoader();
// a listener to listen to events of mcLoader
var listener:Object = new Object();
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
   // tracing out the progress, do your preloader here
   trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " + bytesTotal);
}
listener.onLoadInit = function (Void):Void {
   // once the image is loaded, we will offset it's _x and _y according to it's _width & _height
   image._x = 0 - image._width / 2;
   image._y = 0 - image._height / 2;
}
// registers the listener to mcLoader
mcLoader.addListener(listener);
// load the image
mcLoader.loadClip("[URL unfurl="true"]http://www.google.com.sg/intl/en_com/images/logo_plain.png",[/URL] image);

Regards. Web Hosting - Web Design
03/13/05 -> OLDNEWBIE VS FLASHKIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top