Tag: Action Script 2.0

Simple AS3 Preloading

by Sagar Awasthi on May.28, 2009, under Action Script 2.0, Adobe Flex, Dreamweaver, Flash Banners, Flash Website, Simple AS3 Preloading

I recently tried on preloading in AS3, and then I felt like sharing  something much more simple and easier to understand. I was facing lot  of trouble on Preloader earlier. I learned new methods of using the  loader class and loading main swf into a “container” SWF file. But  this one is extremly simple method, like in AS2 we create a preloader  scene, make it the first scene, and then add 3 frames, and two layers,  on one layer just add a progres bar & a text field. There is some code  required to place on each frame to process the loading of the movie. On the first frame there is code to manage the text display, other  will have preloader progress.

On first frame, In Action Script2, we had this

var progressNum:Number = this.getBytesLoaded() / this.getBytesTotal;
myTextField.text = “Loading: ” + Math.round(progressNum * 100);
myCustomProgressBar.width = progressNum * (a number representing the  full width you want at 100%);

But for our AS3 preloader, we’ll place this rather:

var progressNum:Number = this.loaderInfo.bytesLoaded/
this.loaderInfo.bytesTotal;
myTextField.text = “Loading: ” + Math.round(progressNum * 100);
myCustomProgressBar.width = progressNum * (a number representing the  full width you want at 100%);

Note that instead of a custom progress bar we can simply add the AS3  progress bar the stage and use this code in the place of the “myCustomProgressBar.width…” line
For the second frame in AS2, We used

if(this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal){
gotoAndPlay(3);
}else{
gotoAndPlay(1);
}

And finally on the third and last frame of the preloader scene, where  we used to have this in AS2:

gotoAndPlay(”Scene 1 Name”, 1);

& now we’ll have:

gotoAndPlay(1, “Scene 1 Name”);

That’s it!

hope I made myself clear…

Almost the exact same code as AS2, just a little tit-bits or shifting  some things here and there.

  • Share/Save/Bookmark
Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...