Width of a dynamicly loaded jpg?

Hello,
sorry if this has been already asked and replied, i couldn’t find the answers i’m looking for…

I’m loading a pic using a config file like:

[AS]
onClipEvent (load) {
loadText = new LoadVars();
loadText.load(“config.txt”);
loadText.onLoad = function() {
if (this.imageurl != 0) {
_root.createEmptyMovieClip(“img”, 10);
loadMovie(this.imageurl, _root.img);
//trace(_root.img._width)
}
};
}
[/AS]

Now i’d like to check the width and height of the loaded pic by checking the height and width of the holder MC but it always returns 0… Can someone help?

TiA :slight_smile:

Retrieve the width of the movie clip after it is fully loaded:

loadText = new LoadVars();
loadText.load("config.txt");
loadText.onLoad = function() {
	if (this.imageurl != 0) {
		_root.createEmptyMovieClip("img", 10);
		_root.createEmptyMovieClip("loader", 11);
		loadMovie(this.imageurl, _root.img);
		_root.loader.onEnterFrame = function() {
			if (_root.img.getBytesLoaded() == _root.img.getBytesTotal()) {
				trace(_root.img._width);
				_root.loader.removeMovieClip();
			}
		};
	}
};

It’s not working…

[AS]
onClipEvent (load) {
loadText = new LoadVars();
loadText.load(“config.txt”);
loadText.onLoad = function() {
if (this.imageurl != 0) {
_root.createEmptyMovieClip(“img”, 10);
_root.createEmptyMovieClip(“loader”, 11);
loadMovie(this.imageurl, _root.img);
_root.loader.onEnterFrame = function() {
if (_root.img.getBytesLoaded() == _root.img.getBytesTotal()) {
trace(_root.img._width);
_root.loader.removeMovieClip();
}
};
}
};
}
[/AS]

something wrong???

Thanks for your time

Ops, replace this line:

if (_root.img.getBytesTotal() && _root.img.getBytesLoaded() == _root.img.getBytesTotal()) {

w00t it works, thanks a bunch :} :}

Welcome :slight_smile:

One question tho, can you explain that line to me??

[AS]
if (_root.img.getBytesTotal() && _root.img.getBytesLoaded() == _root.img.getBytesTotal()) {
[/AS]

cause i don’t understand why if (_root.img.getBytesLoaded() == _root.img.getBytesTotal()){ isn’t enough …

:slight_smile:

Because when you create the empty movieclip, it has 0kb.
So for a brief instant, _root.img.getBytesLoaded() == _root.img.getBytesTotal() will be true (they will be both equal to zero) before you load the movie.
To avoid that, we check if _root.img.getBytesTotal() is not equal to zero.

got it, thanks again for your help, very much apreciated :slight_smile: :slight_smile: