Flv buffer animation

respected programmers,

i am trying to make a flv http progressive download mechanism.
the mechanism involves a preloader to show when the buffer is refilling.

My code is like this:

if(infoObject.code.toString()==‘NetStream.Buffer.E mpty’)
var ldr:MovieClip=_root.attachMovie(“loader”,“loader”, 0);
if(infoObject.code.toString()==‘NetStream.Buffer.F ull’)
if(infoObject.code.toString()==‘NetStream.Buffer.F lush’)

However i notice that , each time the buffer fills up, the stream starts playing before the loader is removed from screen. I want to to know, why this lag is there.

also how can i solve this problem , so that each time the buffer is full again, the loader should be removed first and then the stream should play.