# Loading .jpg to MC

**URL:** <https://forum.kirupa.com/t/loading-jpg-to-mc/61870>\
**Category:** Uncategorized\
**Created:** [August 22, 2004, 11:24pm UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870 "2004-08-22T23:24:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![murka390](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@murka390](https://forum.kirupa.com/u/murka390)\
**Post date:** [August 22, 2004, 11:24pm UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/1 "2004-08-22T23:24:27Z")

</div>

whats the problem with my script? :h: /// action goes inside the movieclip “piltpilt”. i need to load a .jpg file to the MC “pilt2”(it’s inside “piltpilt”) and if the width of the .jpg loaded to “pilt2” is over 201 px, then the width of MC “piltpilt” must be 274 and height must be 200.  
But there appears no change in width.

my script:

algus = \_root[“t”+\_parent.\_parent.\_currentframe];  
[COLOR=DarkRed]this.createEmptyMovieClip(“pilt2”, 1);  
this.pilt2.loadMovie(“valmis/”+algus+".jpg");  
if (pilt2.\_width\>200) {  
\_parent.piltpilt.\_width = 274;  
\_parent.piltpilt.\_height = 200;  
}[/COLOR]\_root.kell = valma;

---

<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:** [August 22, 2004, 11:39pm UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/2 "2004-08-22T23:39:05Z")

</div>

you have to wait until its loaded before you can check its width. Jpeg loading isnt immediate. It takes time. set an interval with setInterval or use onEnterFrame to check to see when its loaded and then check the width

---

<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:** [August 23, 2004, 8:32am UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/3 "2004-08-23T08:32:42Z")

</div>

whats wrong with this??  
it SHOULD wait until the picture is loaded, and then take it’s width, height and reseize the “piltpilt” movieclip  
(i DO have to use the instance names to identidy movieclips? cause’ i have used only instance names)  
HELP ME

algus = \_root[“t”+\_parent.\_parent.\_currentframe];  
piltpilt.createEmptyMovieClip(“pilt2”, 1);  
piltpilt.pilt2.onLoad = function() {  
do {  
loadMovie(“valmis/”+algus+".jpg", 2);  
l = this.getBytesLoaded();  
t = this.getBytesTotal();  
} while (t != 0 && Math.round(l/t) == 1);  
if (l == t) {  
w = this.\_width;  
h = this.\_height;  
\_parent.\_parent.piltpilt.\_width = w;  
\_parent.\_parent.piltpilt.\_height = h;  
}  
};  
\_root.kell = valma;

---

<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:** [August 23, 2004, 10:32am UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/4 "2004-08-23T10:32:34Z")

</div>

I said setinterval or enterframe, NOT while of for loops. while and for loops are for “immediate” looping. You need something that happens over time.

If you’re using MX04, try using the moviecliploader

---

<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:** [August 23, 2004, 11:03am UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/5 "2004-08-23T11:03:08Z")

</div>

i’m using regular Flash MX  
setintervals - with that i’m not familliar  
enterframe?

now…  
if i put the next script to the 1. frame of the movieclip “piltpilt” (there is 2 frames… the 2. is empty), it shows the loaded .jpg(w = 200, h = 274) when i test the movie.(but when it loads a .jpg that has… \_width = 274 and \_height = 200, then i need that “piltpilt” resizes to w = 274 and h = 200 and goes to new \_x and \_y)

[COLOR=Navy]algus = \_root[“t”+\_parent.\_parent.\_currentframe];  
this.createEmptyMovieClip(“pilt2”, 1);  
loadMovie(“valmis/”+algus+".jpg", \_pilt2);[/COLOR]

and do i put the next script to the movie clip “piltpilt” (\_parent to pilt2)…?

[COLOR=Navy] onClipEvent (enterFrame) {  
t = pilt2.getBytesTotal();  
l = pilt2.getBytesLoaded();  
if (t != 0 && Math.ceil(t/l) == 1) {  
this.\_width = 274  
this.\_height = 200;  
this.\_x = -94.0;  
this.\_y = -112.0;  
}  
}[/COLOR]

but anyways… it does’nt work and i’m PRETTTYY confused with that thing for now…have been doing the game pretty much 24h in a row and it pisses of if something just does not want to work.

could You PLEASE help me to fix the script or fix the mistakes and explain me, what where goes  
PLEASE PLEASE  
PLEASE  
PLEASE  
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:** [August 23, 2004, 11:50am UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/6 "2004-08-23T11:50:39Z")

</div>

hm… is this better? i’ve put this into the first frame of MC “piltpilt”. The picture appears, but there is still no resizing…

this.onEnterFrame = function() {  
algus = \_root[“t”+\_parent.\_parent.\_currentframe];  
this.createEmptyMovieClip(“pilt2”, 1);  
this.loadMovie(“valmis/”+algus+".jpg", \_pilt2);  
t = this.getBytesTotal();  
l = this.getBytesLoaded();  
if (t != 0 && Math.ceil(t/l) == 1 && pilt2.\_width\>200) {  
this.\_width = 274;  
this.\_height = 200;  
this.\_x = -94.0;  
this.\_y = -112.0;  
}  
};

---

<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:** [August 23, 2004, 2:35pm UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/7 "2004-08-23T14:35:29Z")

</div>

OK!  
i have made a .fla, that contains pretty much the same situation as in my original .fla  
i have tried to use setInterval, but things just wount work for me.

just in case i’d like to mention that the goal with that .fla is to get the dynamic textbox in \_root to say “correct!” and the width of the shape on \_root must be 500.  
conditions are, that script must check if the picture is loaded and picture’s height is greater then 200.

[COLOR=DarkRed]i’d be really thankful if someone could make this .fla work[/COLOR]

---

<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:** [August 23, 2004, 8:39pm UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/8 "2004-08-23T20:39:09Z")

</div>

Are your pictures progressive jpeg’s? If so you have to edit them and remove that option, else they simply won’t load in flash…

---

<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:** [August 24, 2004, 6:26am UTC](https://forum.kirupa.com/t/loading-jpg-to-mc/61870/9 "2004-08-24T06:26:43Z")

</div>

they are not progressive… and the DO load in flash, but this script does’nt work a needed ( \_root.asd does’nt get “Correct” and \_root.line does’nt get \_width = 500;

this.createEmptyMovieClip(“pilt2”, 1);  
this.loadMovie(“[http://www.hot.ee/murka390/egeria.jpg](http://www.hot.ee/murka390/egeria.jpg)”, \_pilt2);  
checkLoaded = function () {  
var t = pilt2.getBytesTotal(), l = pilt2.getBytesLoaded();  
if (t != 0 && (l/t) == 1 && pilt2.height\>200) {  
var w = pilt2.\_width, h = pilt2.\_height;  
\_parent.asd = “Correct!”;  
\_parent.line.\_width += 500;  
clearInterval(intervalID);  
}  
intervalID = setInterval(checkLoaded, 50);  
};
