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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you access a loaded .jpgs width and height

Status
Not open for further replies.

rchapin

Programmer
Jun 3, 2004
2
US
I've searched through this forum and only found 1 reference to this problem, although it didn't really give me any clues.

What I'm doing is loading a flash movie on a webpage, passing it variables (urls of .jpgs and strings of text to be displayed with the jpgs) and then displaying them in the movie.

I need to be able to get at the width and height of the loaded .jpgs but flash doesn't seem to be cooperating.

Here's my code:

// Here we create a clip in the main movie.
_root.createEmptyMovieClip("mcInst_photoHolder0_mc", 100);
trace( "The name of our newly created movieClip is " + _root.mcInst_photoHolder0_mc._name );

// Now we'll try to load a jpg into our new movieclip
mcInst_photoHolder0_mc.loadMovie(var_photosArray[0].graphic);

// Now we'll see if we can access the width and height of said clip
trace( "The width of the .jpg in mcInst_photoHolder0_mc = " + _root.mcInst_photoHolder0_mc._width );
trace( "The height of the .jpg in mcInst_photoHolder0_mc = " + _root.mcInst_photoHolder0_mc._height );

I'm able to load the .jpg (the url of which is the var_photosArray[0].graphic ) and display it just fine.

When I try to access the _width or _height parameters I get 0.

???
 
Have you tried your trace after you're sure the .jpg is loaded, and on another frame than the loading action itself?
 
Yeah, what I've actually managed to do is run an onEnterFrame check and I'm noticing that the .jpg isn't fully loaded and initialized until after the 2nd or 3rd frame, so I think that fixed it.

Thanks!

 
You can run a check on the image's load progress then fire the action that reads the width and height when it's fully loaded:

Code:
checkLoad = function () {
	if (loadPoint.getBytesLoaded()>=loadPoint.getBytesTotal()) {
		clearInterval(loadInterval);
		trace(loadPoint._height+" "+loadpoint._width);
	}
};
loadPoint.loadMovie('image.jpg');
loadInterval = setInterval(checkLoad, 250);

Using setInterval here is slightly more efficient that running an event every frame (especially if you're using a high framerate).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top