Preloader problem - please help!

I tried to make a preloader and I got to a problem. I made a masking layer for the bar. I’ve also made 3 dynamic texts (size, loaded and percentage), and I’ve written this AS:

loaded = getBytesLoaded();
size = getBytesTotal();
if (loaded >= size){
percentage = int(loaded/(size/100));

but I don’t know where to put it; any way I do it it just doesn’t work

If anyone knows how to do this, please help.