Your Ad Here

April 11, 2010

Preloader

Title: Preloader in Adobe Flash

Category : Advanced
Actionscript : 2.0

Preloader shows the percentage of the data loaded of the Flash Movie while streaming. It is very useful in Flash Websites. With Actionscript 2 it is very easy to develop a Preloader with few lines of code.

1- Open up Macromedia Flash and create a new file.

2- Create three layers, name the first one as “actions”, second one as “preloader” and the third one as “data”. Now make two empty frames on “actions” and “data” layers.





3- Now create a Movie Clip (Insert> New Symbol> Movie Clip) and name it as “Load-Bar”. In the Movie Clip make a colored square with width=100 and height=10. Delete its outline. In the properties name it as “bar_mc” Make sure it is on the origin i.e. x and y-axis position should be zero.









4- Come back to ‘scene 1’. Create an empty text field and in the properties select “Dynamic Text”. Also in the Properties name it as “percentage”.




5- Now Select the ‘actions’ layer and select its first frame. Open up the Actions Panel and write this script:
stop();
var loadingCall:Number = setInterval(preloadSite, 50);
function preloadSite():Void {
var siteLoaded:Number = _root.getBytesLoaded();
var siteTotal:Number = _root.getBytesTotal();
var percentage:Number = Math.round(siteLoaded/siteTotal*100);
percentage.text = percentage +" %";
bar_mc._width = percentage;
if (siteLoaded >= siteTotal) {
clearInterval(loadingCall);
gotoAndStop(2);
}
}

6- Now select the second frame of actions layer and write this script:
stop();

7- Place your data in the second frame of the “data” layer. Make sure the first frame should be blank.

8- Now test the Movie Clip by Pressing ‘Ctrl+Enter’. Here you will notice that your preloader is seen like a flash, to test it correctly in the present window select ‘View> Stimulate Download’ or you can press ‘Ctrl+Enter’ again.

Description:

>> This will stop the movie on the current frame:
stop();

>> This will create a preloader function and will calculate the percentage of the data loaded. When the datawill be loaded it will jump to frame 2 of the movie clip:
var loadingCall:Number = setInterval(preloadSite, 50);
function preloadSite():Void {
var siteLoaded:Number = _root.getBytesLoaded();
var siteTotal:Number = _root.getBytesTotal();
var percentage:Number = Math.round(siteLoaded/siteTotal*100);
percentage.text = percentage +" %";
bar_mc._width = percentage;
if (siteLoaded >= siteTotal) {
clearInterval(loadingCall);
gotoAndStop(2);
}
}

No comments:

Post a Comment

Please use sensible language.....!