Preloading in Flash – actionscript 2 / actionscript 3

Pre-loaders in flash are kind of pacifiers which let user know that flash movie is getting downloaded and let him know the estimated time left or the percentage of flash file remaining. see example here

This is quite useful for engaging the user otherwise user is unaware of the activity that flash file is getting downloaded (which may take some time in case of bigger files and slow internet speed) and may loose his patience and go to some other website/application.

There are various ways to make Pre loaders in Flash. I worked on this in one of my projects and this how i achieved the Pre-loading status of flash movie.

The actual movie starts from 3rd frame of movie because first 2 frames was reserved for Pre-loader. Code checks status of download on 2nd frame and gotoAndPlay(1) is called which send control to first frame again. So movies runs only in first two frames where download status is checked and status bar or any other UI can be shown to user for status update.

Following are the steps.

1. Create first frame blank.
2. Put controls on 2nd frame to display the download status information.
3. Use following code to show download status info, put this code in action window of 2nd frame:

 
/* get value of bytes downloaded */
myLoaded = Math.round(getBytesLoaded());
/* get total size of flash movie */
myTotal = Math.round(getBytesTotal());
/* Calculate the percentage of movie downloaded */
myPercent = myLoaded/myTotal;
/* loadbar is UI component which is showing percentage downloaded on UI */
loadBar._width = myPercent*210;
/* Load text is UI component which is showing % on UI */
LoadTxt.text = Math.round(myPercent*100)+"%";
if (myLoaded == myTotal) {
    /* if complete movie is downloaded, Proceed */
    gotoAndPlay(3);
} else {
    /* If download is in progress , Go back to first frame*/
    gotoAndPlay(1);
}
 

Initially when I was testing this, I was not getting the UI components which i added to movie for showing download status i.e. loadBar and loadTxt. Then I found the reason.As movie was no completely loaded and its components were also not loaded, it was not showing any UI for pre-loader.

It required some extra configuration which was exporting action script classes of components to first frame. which can be done in following way:

1. Right Click on a component in library and choose Linkage… option.
2. You need to check all Linkage check boxes in this window, default window will look like this:

3. Do this for all custom components you are using for Preloader.

See in video below how Preloaders can be created in AS3 i.e. actionscript 3 which is slightly different from AS2 (actionscript 2) and provided in latest Flash environments (Adobe Flash CS3 and CS4)

source : http://www.gotoandlearn.com

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)