# Problem with preloader for dynamically loaded jpegs

**URL:** <https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375>\
**Category:** flash\
**Created:** [November 13, 2003, 7:48am UTC](https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375 "2003-11-13T07:48:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rave\_t](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rave\_t](https://forum.kirupa.com/u/rave_t)\
**Post date:** [November 13, 2003, 7:48am UTC](https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375/1 "2003-11-13T07:48:48Z")

</div>

I use this code to display the progress of the jpeg im loading dynamically into my empty movieclip, bildholder.

bytes\_loaded = Math.round(bildholder.getBytesLoaded());  
bytes\_total = Math.round(bildholder.getBytesTotal());  
getPercent = bytes\_loaded/bytes\_total;  
loadpic = “\_loading\_product “+Math.round(getPercent\*100)+” % loaded”;  
if (bytes\_loaded \>= bytes\_total) {  
gotoAndPlay(“done”);  
}

The problem is that I cant get the line:  
bytes\_total = Math.round(bildholder.getBytesTotal());

to work. It seems that Flash have a problem getting the TotalBytes for a dynamically jpeg.

When i set bytes\_loaded to a fix number, say 5000, then the preloader works but not wgen I use the command .getBytesTotal()

Can anyone tell me why or how I can solve this problem.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 7:51pm UTC](https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375/2 "2003-11-15T19:51:29Z")

</div>

any one please 🅱

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 8:12pm UTC](https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375/3 "2003-11-15T20:12:17Z")

</div>

```auto
loadPic = function (picture) {
	bildholder.loadMovie(picture);
	preload();
};
preload = function () {
	this.createEmptyMovieClip("temp", 1000);
	temp.onEnterFrame = function() {
		var t = bildholder.getBytesTotal(), l = bildholder.getBytesLoaded();
		if (t && !isNaN(t)) {
			var percent = Math.round(l*100/t);
			if (l == t) {
				myTextField.text = "Done Loading";
				this.removeMovieClip();
			} else {
				myTextField.text = percent+" %";
			}
		}
	};
};
myButton.onPress = function() {
	loadPic("picture.jpg");
};

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 10:36pm UTC](https://forum.kirupa.com/t/problem-with-preloader-for-dynamically-loaded-jpegs/35375/4 "2003-11-15T22:36:06Z")

</div>

try including some \_root or \_parent bits because when you load the movie, you have to make sure the loaded movie is talking to itself, not the root timeline of the main movie.
