# Another goofy MX quesiton regardng preloading for external JPEG's

**URL:** <https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797>\
**Category:** flash\
**Created:** [February 18, 2003, 7:42am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797 "2003-02-18T07:42:05Z")\
**Posts on this page:** 15\
**Page:** 3

<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:** [June 16, 2003, 9:04am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/41 "2003-06-16T09:04:07Z")

</div>

Could someone please post the final fla as i can’t ge this to work for some reason.

---

<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:** [June 17, 2003, 2:03pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/42 "2003-06-17T14:03:46Z")

</div>

Great! setting the variable with \_root.x works and solves that problem.

However, checking when the border is the same size as the picture (taking account of the added width) is being problematic. I also have a less than elegant way of checking - but works sort of!

I have the following code in a separate MC with two frames to create a loop. Frame 2 is empty and Frame 1 has the following:

[AS]  
if ((\_root.border.\_width\>(\_root.picture.\_width+39)) &&  
(\_root.border.\_height\>(\_root.picture.\_height+39))) {  
\_root.picture.\_visible = 1;  
\_root.textBox.\_visible = 1;  
}  
[/AS]

I have tried to put this on the border MC but it doesn’t work.  
One problem is that == doeszn’t work in the above script - any suggestions? The use of ‘\>’ is not ideal and not accurate enough with the timing in making the picture visible.

---

<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:** [June 17, 2003, 3:29pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/43 "2003-06-17T15:29:22Z")

</div>

Frame loops are for Flash 4 😛

onClipEvent(enterFrame) is Flash 5 and Flash MX on a movie clip.

this.onEnterFrame = function() {//code here} is Flash MX on a frame.

As for why == doesn’t work, it is because you are using the easing equation and the numbers you get by dividing by the speed aren’t going to be exactly equal to the end number.

Maybe try working with Math.floor(), Math.round(), or Math.ceil() to round the number appropriately and possibly fix that problem.

I came up with this for someone at [actionscript.org](http://actionscript.org) the other day. It was used for scaling fading but still using the easing equation and deletes the onEnterFrame command appropriately (man was that a task). It could be used just for scaling as well though with a little editing (removing anything dealing with alpha)

[AS]MovieClip.prototype.initiateFader = function(inOrOut, finalX, finalY, finalA, speed) {  
this.onEnterFrame = function() {  
if (inOrOut == “fadeOut”) {  
this.\_xscale += (finalX-this.\_xscale)/speed;  
this.\_yscale += (finalY-this.\_yscale)/speed;  
this.\_alpha += (finalA-this.\_alpha)/speed;  
this.xs = Math.floor(this.\_xscale);  
this.ys = Math.floor(this.\_yscale);  
this.af = Math.floor(this.\_alpha);  
} else if (inOrOut == “fadeIn”) {  
this.\_xscale += Math.ceil((finalX-this.\_xscale)/speed);  
this.\_yscale += Math.ceil((finalY-this.\_yscale)/speed);  
this.\_alpha += Math.ceil((finalA-this.\_alpha)/speed);  
this.xs = Math.ceil(this.\_xscale);  
this.ys = Math.ceil(this.\_yscale);  
this.af = Math.ceil(this.\_alpha);  
}  
trace(this.xs+" : “+this.ys+” : "+this.af);  
if (this.xs == finalX && this.ys == finalY && this.af == finalA) {  
trace(“transition complete”);  
this.\_xscale = finalX;  
this.\_yscale = finalY;  
this.\_alpha = finalA;  
delete this.onEnterFrame;  
}  
};  
};  
HitArea.onRollOver = function() {  
this.initiateFader(“fadeOut”, 75, 50, 50, 6);  
};  
HitArea.onRollOut = function() {  
this.initiateFader(“fadeIn”, 100, 100, 100, 6);  
};[/AS]

---

<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:** [June 17, 2003, 4:32pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/44 "2003-06-17T16:32:19Z")

</div>

Thank you - I will go away and play around with the script you have kindly provided - but I might be back!! 😉

As for the loop - yep - soooo flash 4 - but because I recently upgraded I am learning loads ( this thread alone has made me really try and get to grips with the scripting believe it or not)

As for the == , your explanation makes perfect sense!

Osc

---

<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:** [June 20, 2003, 8:39am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/45 "2003-06-20T08:39:21Z")

</div>

Hi again!  
Because the macromedia gallery example does not have a preloader - I tried to adapt the scripts from earlier in this thread to make a pseudo back and forward button - it works - I can easily go back and forward - but the preloader part does not work.

Is it possible to have an if within if???

This is the back button example… the \_root.b variable is set by the first thumbnail that is pressed - ie so when I delete 1 from n, it will call the previous sibling in the script.

[AS]  
on (release)  
{  
if ((n\>0) && (n\<=3)) {  
var n = ((\_root.b–)-1);  
trace("n "+n)  
this.createEmptyMovieClip(“preloader”,1000  
\_root.picture.picture2.loadMovie(pictures.childNodes[0].childNodes[n].attributes[“jpegURL”]);  
picture.\_visible = false;  
loadBar.\_visible = 1;  
textBox.\_visible = false;  
preloader.onEnterFrame = function() {  
var l = picture.getBytesLoaded();  
var t = picture.getBytesTotal();  
var getPercent = l/t;  
loadBar.\_width = getPercent\*100;  
if (l\>0 && l\>=t) {  
trace(“loaded back”);  
textBox.picTitle =  
pictures.childNodes[0].childNodes[n].childNodes[0].nodeValue;  
picture.\_visible = 1;  
textBox.\_visible = 1;  
loadBar.\_visible = false;  
\_root.x = picture.\_width;  
\_root.y = picture.\_height;  
delete this.onEnterFrame;  
}  
}  
}  
[/AS]

---

<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:** [June 20, 2003, 8:22pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/46 "2003-06-20T20:22:24Z")

</div>

[AS]delete this.onEnterFrame;[/AS]

It stopped working because you made it stop running 😉

---

<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:** [June 21, 2003, 4:17pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/47 "2003-06-21T16:17:37Z")

</div>

Hey All,

This is a very useful thread and I have done a little tweak allowing the loading of random images…(I know, simple stuff!)

All I was wandering is what would I have to tweak in order to have the loaded image/movieclip fade gradually using actionscript.

* * *

stop();  
footers = 6;  
randomnumber = Math.ceil(Math.random()_footers)  
this.createEmptyMovieClip(“preloader”, 1000);  
this.createEmptyMovieClip(“container”, 1001);  
container.loadMovie(randomnumber add “.jpg”);  
container.\_visible = false;  
preloader.onEnterFrame = function() {  
var l = container.getBytesLoaded();  
var t = container.getBytesTotal();  
var getPercent = l/t;  
loadText = Math.round(getPercent_100)+"%";  
loadBar.\_width = getPercent\*100;  
if (l\>0 && l\>=t) {  
container.\_visible = 1;  
delete this.onEnterFrame;  
play();  
}  
};

* * *

I know I would have to change \_visible to \_alpha and maybe use a onEnterFrame command to increase the \_alpha - but I am stuck!

Any help would be greatly appreciated!

mecha

---

<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:** [June 21, 2003, 4:19pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/48 "2003-06-21T16:19:14Z")

</div>

[http://www.kirupa.com/developer/mx/photogallery.htm](http://www.kirupa.com/developer/mx/photogallery.htm) :sigh:

---

<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:** [June 22, 2003, 11:13am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/49 "2003-06-22T11:13:32Z")

</div>

Hello!

Having got everything to work so far - I seem to have stumbled on an even more elementary problem. The script that you have been helping with works great if the buttom is on the main stage - however, if I try and button the AS in a button in another MC, it doesn’t work.

In other words, the picture MC is placed on the main stage, I then have an MC1 with an MC2 within it. The buttons are on MC2 - however, it doesn’t work…

even this doesn’t work:  
[AS]  
\_root.picture.picture2.loadMovie(pictures.childNodes[0].childNodes[1].attributes[“jpegURL”]);  
[/AS]

Surely the \_root takes care of the path??

Osc

---

<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:** [June 22, 2003, 12:28pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/50 "2003-06-22T12:28:31Z")

</div>

Got it to work - and yes it was obvious - I had forgotten to add the \_root to the path for the xml file, and not just the picture MC!!

Osc

---

<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:** [June 25, 2003, 3:24pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/51 "2003-06-25T15:24:16Z")

</div>

just reading through some posts and … what happened lostinbeta. you seem so bitter now. _sniffle_ i miss the old ‘happy to help’ beta

---

<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:** [June 25, 2003, 3:48pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/52 "2003-06-25T15:48:59Z")

</div>

> \*Originally posted by shuga \*  
> \*\*just reading through some posts and … what happened lostinbeta. you seem so bitter now. _sniffle_ i miss the old ‘happy to help’ beta \*\*

I’m still that guy… sometimes (-:

I think here I was just reaching my limit on preloader questions, it’s been built up over the past few weeks after mass amounts of preloader questions via the forum, my PM Inbox, and my e-mail. But now I think I am better, as my footer states I don’t accept Flash questions in my PM Inbox (defeats the entire purpose of the forum) and I am now officially retired from preloader questions, there is most likely nothing someone can ask about preloaders that they can’t find on the forum by searching by now. :cyclops:

---

<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 9, 2003, 10:45pm UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/53 "2003-08-09T22:45:58Z")

</div>

Hello guys! I was following your post, but i got lost.

Because my images are in .swf and not jpeg. and also I am a Flash Newbie.

Is there a way to create thesame thing? that when you click on the button, it shows the preloader first before it displays the image to an empty movieclip on another .swf, before it loads to the main movie.

I try another way of creating it but I think its a bit daft. I try adding a preloader on one images, but it doesnt work. the loading animation is still there visible and keeps on playing so i decided to stop. And oh yah… because i had 38 images i think it will take me ages to finish this project.

this might help you what i meant to do. heres the add of my site.

www.metalgurl.tk

noticed the gallery, if you had a DSL connection you’ll be alright, but how about our Dial UP friend?

Your help are always appreciated. thanks!

---

<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:** [July 13, 2004, 9:47am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/54 "2004-07-13T09:47:32Z")

</div>

> [@lostinbeta](#):
>
> ```php
> this.createEmptyMovieClip("preloader", 1000);
> this.createEmptyMovieClip("container", 1001);
> container.loadMovie("yourImage.jpg");
> container._visible = false;
> preloader.onEnterFrame = function() {
> var l = container.getBytesLoaded();
> var t = container.getBytesTotal();
> var getPercent = l/t;
> loadText = Math.round(getPercent*100)+"%";
> loadBar._width = getPercent*100;
> if (l>0 && l>=t) {
> container._visible = 1;
> delete this.onEnterFrame;
> }
> };
> 
> ```
> 
> That is the code I used.
> 
> loadText is a dyanmic textbox on the stage with the VAR name (not instance name) of “loadText” and it shows the percent loaded.
> 
> loadBar is a movie clip on the stage with the instance name “loadBar” and its width increases depending on the amount loaded (note: change the 100 in this line to the final width of your loadBar clip).
> 
> EDIT: Here is my code in action. [VIEW HERE](http://www.lostinbeta.com/images/dynamicPreloader.html)

hmm, i am trying your code and i get NAN and then it jumps to 100% and the loadbar as well. Your code is just on the root, right???

---

<div class="post-metadata">

**Author:** ![milesdavis](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@milesdavis](https://forum.kirupa.com/u/milesdavis)\
**Post date:** [April 25, 2006, 6:19am UTC](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797/55 "2006-04-25T06:19:37Z")

</div>

Hmm… I don’t get the ‘yourImage.jpg’. How does this work exactly – if you’re loading dynamic information into a movieclip? For example - using an infinite menu and XML, it loads jpegs with various names which change, how can we pin it down to 'yourImage.jpg"? I’m confused I think.

Basically, I want there to be a pre-loader that appears as my dynamic jpeg or SWF is being loaded. I tried the above code, no luck.

Thanks for any info!

-md

[Previous page](https://forum.kirupa.com/t/another-goofy-mx-quesiton-regardng-preloading-for-external-jpegs/13797.md?page=2)
