Preloader with percent loaded


// This script must have two keyframes:
// FIRST KEYFRAME ————————

// The first step is create a text field with variable name "loadedField". In that field,
// Flash gonna paste the porcent loaded for the movie in text format.
percent = Math.floor(getBytesLoaded()/getBytesTotal()*100);
loadedField = percent+"% loaded of "+Math.floor(getBytesTotal()/1024)+"kb";

// The second step is create the progress bar. With the rectangle tool we drag
// and create, then convert to movie clip symbol with the variable name "bar".
// If you see in the script, we use the property "_xscale". In that way, flash apply in
// horizontal mode the percent loaded to the symbol "bar".
if(percent != 100){
        setProperty(bar, _xscale, percent);
}

// The third step is to check for loaded file. If the percent loaded is 100%, then go
// to the frame where the animation begin. I prefer put the preloader on one scene
// and the animation in another.
if (percent == 100) {
        gotoAndPlay("escene2″, "1″);
}

// SECOND KEYFRAME ————————

// Put this script in the second keyframe.
gotoAndPlay(1);
// On this way, the movie loop till the file become 100% loaded.

你可以延伸閱讀以下文章:

網友回應

Tags: