Skip to main content
Inspiring
August 25, 2007
Answered

Finding the width of a JPEG loaded into a movie clip

  • August 25, 2007
  • 3 replies
  • 281 views
I will be loading a page of bio information. Next to the person's photo (photos will vary in width) I want to put a column of buttons about 20 pixels to the right of the photo. So after I load the photo into an empty movie clip, I'm trying to get the width of the photo in order to figure out the x position of the buttons next to it. Here is what I have:

myImage = "images/" + _level0.images[link];
loadMovie(myImage,image_mc);
// JPEG loads okay into image_mc //

trace("image_mc._x = " + image_mc._x);
// I get "Image_mc._x = 393" as expected //

trace("myImage._width = " + myImage._width);
// I get "image_mc._width = undefined" //

trace("image_mc._width = " + image_mc._width);
// I get "image_mc._width = 0" //

How do I find the width of the loaded JPEG?
This topic has been closed for replies.
Correct answer Damon Edwards
you are probably trying to get the width before the image has loaded completely.. use the MovieClipLoader class to load the image into the empty movie clip, then use the onLoadInit event to get the movie clips's width(which is the images width);

var mcLoader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myListener.onLoadInit = function(target:MovieClip):Void{
trace(image_mc._width);
};
mcLoader.addListener(myListener);
mcLoader.loadClip(myImage, image_mc);

3 replies

Damon Edwards
Inspiring
August 25, 2007
no problem.
pbesongAuthor
Inspiring
August 25, 2007
Outstanding! Thanks, dzedward. That worked perfectly. The link buttons now automatically move to the right of each picture no matter how wide they are. I really appreciate your help!
Damon Edwards
Damon EdwardsCorrect answer
Inspiring
August 25, 2007
you are probably trying to get the width before the image has loaded completely.. use the MovieClipLoader class to load the image into the empty movie clip, then use the onLoadInit event to get the movie clips's width(which is the images width);

var mcLoader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myListener.onLoadInit = function(target:MovieClip):Void{
trace(image_mc._width);
};
mcLoader.addListener(myListener);
mcLoader.loadClip(myImage, image_mc);