# Preloader help

**URL:** <https://forum.kirupa.com/t/preloader-help/15747>\
**Category:** Uncategorized\
**Created:** [March 17, 2003, 8:20pm UTC](https://forum.kirupa.com/t/preloader-help/15747 "2003-03-17T20:20:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [March 17, 2003, 8:20pm UTC](https://forum.kirupa.com/t/preloader-help/15747/1 "2003-03-17T20:20:28Z")

</div>

i have an animation that can be 100 frames long but it’s not necissarily so.

i would like this animation to be my preloader basically i want to write a script that gets the bytesloaded/totalbytes and makes a percentage and then goes to the frame corresponding to the percentage

so if my animation is 50 frames long and the movie is found to be 50% loaded by the script then the playhead should be on frame 25.

does that make sense?

thanks very much for your help

---

<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:** [March 17, 2003, 8:25pm UTC](https://forum.kirupa.com/t/preloader-help/15747/2 "2003-03-17T20:25:09Z")

</div>

Well you need to take whats loaded, divide it by the total. multiply by 100 and then tell the movie to gotoAndStop at that frame…

```auto

nTotal = _root.getBytesTotal()/1000;
nLoad = _root.getBytesLoaded()/1000;
nPrecent = Math.round((nLoad/nTotal)*100);
_root.gotoAndStop(nPercent);

```

Now that code will have to go in a movieclip with an enterFrame command, and that moveclip will have to be present in every frame…

---

<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:** [March 17, 2003, 9:25pm UTC](https://forum.kirupa.com/t/preloader-help/15747/3 "2003-03-17T21:25:37Z")

</div>

no … that will only work if you have a 100 frame clip

b/c it goes to the frame that is the percentage number

look at the example i typed … so if my animation is 50 frames long and the movie is found to be 50% loaded by the script then the playhead should be on frame 25.

---

<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:** [March 17, 2003, 9:28pm UTC](https://forum.kirupa.com/t/preloader-help/15747/4 "2003-03-17T21:28:44Z")

</div>

nNumber = Math.round(\_totalframes \* (nPercent/100))

gotoAndStop(nNumber)

---

<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:** [March 17, 2003, 10:22pm UTC](https://forum.kirupa.com/t/preloader-help/15747/5 "2003-03-17T22:22:45Z")

</div>

here’s what i have

```php

nTotal = _root.getBytesTotal()/1000;
nLoad = _root.getBytesLoaded()/1000;
nPercent = Math.round((nLoad/nTotal)*100);
percentage.text = nPercent;
nNumber = Math.round(_totalframes*(nPercent/100));

if (nLoad < nTotal) {
	gotoAndStop(nNumber);
}
if (nLoad == nTotal) {
	gotoAndPlay ("main", 1);
}

```

why isn’t it working?

percentage.text is a text box i have in it’s own layer that i want to display the current percentage in text form while the load is in progress

---

<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:** [March 17, 2003, 10:41pm UTC](https://forum.kirupa.com/t/preloader-help/15747/6 "2003-03-17T22:41:40Z")

</div>

Do you have a loop?

\_root.onEnterframe = function() {

//code goes here

}

---

<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:** [March 17, 2003, 11:00pm UTC](https://forum.kirupa.com/t/preloader-help/15747/7 "2003-03-17T23:00:57Z")

</div>

like this?

```php

nTotal = _root.getBytesTotal()/1000;
nLoad = _root.getBytesLoaded()/1000;
nPercent = Math.round((nLoad/nTotal)*100);
percentage.text = nPercent+"%";
nNumber = Math.round(_totalframes*(nPercent/100));
_root.onenterframe = function(){
if (nLoad == nTotal) {
	gotoAndPlay("main", 1);
} else {
	gotoAndStop(nNumber);
}
}

```

---

<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:** [March 17, 2003, 11:07pm UTC](https://forum.kirupa.com/t/preloader-help/15747/8 "2003-03-17T23:07:45Z")

</div>

no,

```auto
_root.onEnterFrame = function(){
     nTotal = _root.getBytesTotal () / 1000;
     nLoad = _root.getBytesLoaded () / 1000;
     nPercent = Math.round ((nLoad / nTotal) * 100);
     nRemain = nTotal - nLoad;
     percentage = nPercent + "%";
     nNumber = Math.round (_totalframes * (nPercent / 100));
     _root.movieClip._alpha = nPercent;
     if (nRemain <= 0 && nLoad != 0) {
           gotoAndPlay ("main", 1);
     }
};

```

and use a tween just give that MovieCLip the instance name “movieClip” and change its alpha. thats what i did with that file.

[http://www.livetoskateboard.com/test/bleh2.fla](http://www.livetoskateboard.com/test/bleh2.fla)

---

<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:** [March 17, 2003, 11:50pm UTC](https://forum.kirupa.com/t/preloader-help/15747/9 "2003-03-17T23:50:06Z")

</div>

right … i could just tween the symbol with action script … but i’d like to be able to put any animation in there that i want

=)

thanks very much … i’m going to go try it out

---

<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:** [March 18, 2003, 12:02am UTC](https://forum.kirupa.com/t/preloader-help/15747/10 "2003-03-18T00:02:21Z")

</div>

em … i’m a complete \*\*\*\*\*\*\*

i saved over my original file b/c i got the preloader working the way i want it to … but now the buttons don’t work

what happened to them? (i.e. load the site and try to click a button)

---

<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:** [March 18, 2003, 12:14am UTC](https://forum.kirupa.com/t/preloader-help/15747/11 "2003-03-18T00:14:27Z")

</div>

well i made it work again … i also changed the name from bleh to site.fla … [http://www.aaronsleeper.com/site.fla](http://www.aaronsleeper.com/site.fla)

but i guess i can’t have a preloader.  
i made the preloader work … but at the cost of my buttons in the next scene. i don’t see any conflicts but then again i probably missed something.

stupid scenes  
i wish i could have a preloader ☹
