# Can't get Netstream buffer to preload

**URL:** <https://forum.kirupa.com/t/cant-get-netstream-buffer-to-preload/307697>\
**Category:** flash\
**Created:** [April 8, 2010, 3:15pm UTC](https://forum.kirupa.com/t/cant-get-netstream-buffer-to-preload/307697 "2010-04-08T15:15:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eerdepeer](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@eerdepeer](https://forum.kirupa.com/u/eerdepeer)\
**Post date:** [April 8, 2010, 3:15pm UTC](https://forum.kirupa.com/t/cant-get-netstream-buffer-to-preload/307697/1 "2010-04-08T15:15:26Z")

</div>

Hi, I’m trying to make a preloader for the buffer for a 19MB video. I can trace everything, but the math won’t do.

Preloading the video itself is no problem. But what I want is to make a xx% preloader for the buffer of this video.

This is my code. I’ve made a 10ms timer to check the progress of the video.

```auto
var myTimer:Timer = new Timer(10);
myTimer.addEventListener(TimerEvent.TIMER, checkBytesLoaded);

function checkBytesLoaded(e:TimerEvent) {
	// creating a var of the buffertime / total time
    var bufferPercent:Number = ns.bufferTime / objInfo.duration;
    // normally ns.bytesLoaded / ns.bytesTotal gives the outcome of 100%
    var pctLoaded:Number = (ns.bytesLoaded / (bufferPercent * ns.bytesTotal)) * 100;

        // the textbox should be filled with a number + %.
	preload._loader.text = pctLoaded + "%";
    if (pctLoaded>=100) {
	startVideo();
       preload._loader.text = "";
}

```

Tracing deliveres this:  
bytesloaded = 19.813442  
bufferTime = 45  
objTotalTime = 93.333  
bytesTotal = 19.813442  
pctloaded = 814221503081318.8

So in theory, the function must act like this:  
(ns.bytesLoaded / (ns.bufferTime / objInfo.duration \* ns.bytesTotal)) \* 100 = %

When the video is buffering, I can see my computer is downloading the buffer bytes (in MenuMeters) but the preloader is only showing a value when the buffer is full and the video is playing. When the buffering is being loaded, nothing happens with the preloader values.

If I change the pctLoaded into ns.bytesLoaded, I see the value go up when the buffer is loading. What is wrong with this script?
