fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotHow to make a simple Flash preloader

When using Flash content, it is important to preload the file. We do this for a variety of reasons, the main one being that Flash content is inevitably heavier on bandwidth than plain HTML (but the benefits far outweigh this small downside), and so our users are not left staring at a blank screen wondering what is happening we provide them a nice animation, and generally some loading information, to keep them amused.

In this article we will cover how to build a very simple preloader sequence that can be applied to many SWF files.

This, of course, is just one way of preloading Flash content and may not suit every application - there are more technical aspects to think of later, such as the amount of content loading into the first frame of the SWF - but it is a very simple solution that can be quickly implemented when needed.

We have written this article for both ActionScript 2 and ActionScript 3, so you can pick the version most appropriate to you below, and skip straight to that section.

ActionScript 2

What we want to do is set up a separate scene before our main content. In that scene we will have two frames. In our second frame we will measure how much of our current movie is loaded, and if it is not fully loaded we will jump back to the first frame to try again. The movie will jump between these two frames until the content is fully loaded, at which point we will, essentially, let the playhead move passed and into the real content scene of our movie.

So, we need to set up a blank scene with two key frames. We will leave the first keyframe blank, and on the second keyframe we will put the following code:

if (this.getBytesLoaded() < this.getBytesTotal()) {

this.gotoAndPlay(1);

}

And that is all the code we need. This simply checks to see if the number of bytes loaded (getBytesLoaded) is less than the total number of bytes in the SWF (getBytesTotal) and if it is it will redirect back to the first frame, ready to check again when we come along to this frame again. If the getBytesLoaded equals the total number of bytes in the SWF then the playhead will automatically move onto the first frame of the next scene.

Now, to add an animation here, on a separate layer from the ActionScript, simply add a looping animation to the timeline. As we only have two frames in the main timeline, you will want to put the animation in a separate MovieClip to get the looping effect.

Finally, to get a percentage label on the screen, you will want to divide the bytes loaded by the total bytes and display the result as your percentage. To get a bar, or an object filling up as you load, the easiest way is to create a 100 frame MovieClip with a tween, and direct the play to gotoAndStop at each percentage value - so at 20% loaded it will go to frame 20, etc. But we won't go into that here any more than what we have, as that only complicates our incredibly simple preloader.

*NEW CONTENT* - 06 August, 2009

We have just created a new article which follows on from this one covering how to create a percentage based preloader: http://fcOnTheWeb.com/articles/percentage_preloader/. Check it out.

You can download a blank preloader file, using the code mentioned above, from the link below.

preloader_as2.zip

ActionScript 3

What we want to do is set up a separate scene before our main content. In that scene we will have two frames. In our second frame we will measure how much of our current movie is loaded, and if it is not fully loaded we will jump back to the first frame to try again. The movie will jump between these two frames until the content is fully loaded, at which point we will, essentially, let the playhead move passed and into the real content scene of our movie.

So, we need to set up a blank scene with two key frames. We will leave the first keyframe blank, and on the second keyframe we will put the following code:

if (root.loaderInfo.bytesLoaded < root.loaderInfo.bytesTotal()) {

this.gotoAndPlay(1);

}

And that is all the code we need. This simply checks to see if the number of bytes loaded (loaderInfo.bytesLoaded) is less than the total number of bytes in the SWF (loaderInfo.bytesTotal) and if it is it will redirect back to the first frame, ready to check again when we come along to this frame. If the loaderInfo.bytesLoaded equals the total number of bytes in the SWF then the playhead will automatically move onto the first frame of the next scene.

Now, to add an animation here, on a separate layer from the ActionScript, simply add a looping animation to the timeline. As we only have two frames in the main timeline, you will want to put the animation in a separate MovieClip to get the looping effect.

Finally, to get a percentage label on the screen, you will want to divide the bytes loaded by the total bytes and display the result as your percentage. To get a bar, or an object filling up as you load, the easiest way is to create a 100 frame MovieClip with a tween, and direct the play to gotoAndStop at each percentage value - so at 20% loaded it will go to frame 20, etc. But we won't go into that here any more than what we have, as that only complicates our incredibly simple preloader.

*NEW CONTENT* - 06 August, 2009

We have just created a new article which follows on from this one covering how to create a percentage based preloader: http://fcOnTheWeb.com/articles/percentage_preloader/. Check it out.

You can download a blank preloader file, using the code mentioned above, from the link below.

preloader_as3.zip

ferrari_chris

Cheap Ralph Lauren UK (http://cheapralphlaurenuk.1minutesite.co.uk/) says:

2014-01-17 22:03:07

Gucci Shoes UK, http://www.guccivshoesfactory.net/
Polo Ralph Lauren Outlet Online, http://www.rralphlaurenoutlet.com/
Ralph Lauren Outlet Online, http://www.ralphlaurenipolo.com/
Ralph Lauren UK, http://www.polo-outletstoreonline.com/
Beats by Dre, http://www.discountbeatsbydresale.com/
Sacs Longchamp Pairs, http://www.saclongchamppairs.com/
Canada Goose Outlet, http://www.thecanadagooseoutlet.com/
Hollister UK Shops, http://www.cheaphollistersale.co.uk/
Michael Kors Outlet Online, http://www.michaelkors.so/
Marc Jacobs Outlet, http://www.marcjacobsonsale.com/
Michael Kors Outlet, http://www.michaelkorsr.com/
North Jackets Clearance, http://www.north-faceoutletonlines.net/
Burberry Outlet Online, http://www.burbagssale2013.com/
North Clearance Outlet Online, http://www.north-clearance.com/
Coach Factory, http://www.coach-factories.com/
Coach Outlet Online, http://www.coach-purseonsale.com/
Cheap Ralph Lauren UK, http://cheapralphlaurenuk.1minutesite.co.uk/
http://marcjacobsoutlet-2014.tripod.com/
http://www.michaelkorsoutletr.com/
Michael Kors Outlet
Discount Michael Kors
http://www.michael-korsfactorystore.com/
Michael Kors Outlet
Michael Kors Factory Store
http://www.michaellkorsfactoryonline.com/
Michael Kors Outlet
Discount micheal kors

__________

POLO says:

2014-08-04 03:57:29

http://www.superbagsmarket.com/ Super Bags Market
http://www.nike-jordanshoes.com/ Nike Jordan Shoes
http://www.thebeatsbydre.net/ Beats By Dre Outlet
http://www.michaelusakors.com/ Michael Kors Outlet Online
http://www.polo-tshirts.com/ Ralph Polo Outlet Online
http://www.northsclearance.com/ North Clearace Outlet
http://www.polo-ralphlaurenonline.com/ Ralph Polo Outlet
http://www.guccishoesuk-2014.net/ Gucci Shoes Outlet
http://www.michaelkorsstates.com/ Michael Kors Outlet
http://www.polooutlet-store.com/ Polo Outlet Store
http://www.ralph-laurenhome.com/ Ralph Lauren UK
http://www.marcjacobsonsale.com/ Marc Jacobs On Sale
http://www.mcmworldwides.com/ MCM Outlet
http://www.salongchamppairs.com/ Sac Longchamp Pairs
http://www.canada-gooser.com/ Canada Goose Outlet
http://www.burberrybags2014.com/ Burberry Outlet
http://www.michaelkors.so/ Michael Kors Outlet
http://www.oakley-sunglassfactory.com/ Oakley Sunglaases Factory
http://www.north-faceoutlet.us.com/ North Face Outlet Online
http://www.moncler-clearance.com/ Moncler Clearance
http://www.woolrich-clearance.com/ Woolrich Clearance
http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online
http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online
http://www.monsterbeatsbydres.net/ Monster Beats Outlet
http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet
http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory
http://www.mcmoutlet-jp.com/ MCM 店铺
http://www.cheapdiscountoutlet.com/ Discount Clothes Sale
http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online
http://www.coach-factoryoutlets.net/ Coach Factory Outlet
http://www.coach-blackfriday.net/ Coach Black Friday
http://www.coach-storeoutletonline.com/ Coach Store Outlet Online
http://www.coach-factoryoutletonlines.com/ Coach Factory Outlet Online
http://www.coachcoachoutlet.net/ Coach Outlet
http://www.coach-factory.net/ Coach Factory
http://www.coach-pursesoutlet.net/ Coach Purses Outlet Online
http://www.coach-outletonline.net/ Coach Outlet USA
http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet
http://www.zxcoachoutlet.com/ Coach Outlet Online USA
http://www.mischristmas.com/ Coach Factory Outlet Online
http://www.misblackfriday.com/ Black Friday
http://www.newoutletonlinemall.com/ Coach Purses Outlet Online
http://www.clickmichaelkors.com/ Michael Kors USA
http://www.cmichaelkorsoutlet.com/ Michael Kors Outlet USA
http://www.ralphlaurenepolo.com/ Ralph Lauren Polo

__________

hollister clothing store (http://www.rayban--sunglass.com/) says:

2014-08-05 03:26:25

http://www.rayban--sunglass.com/ ray ban sunglasses
http://www.customscopyright.com/ coach factory outlet
http://www.hollisterclothing-store.com/ hollister clothing store
http://www.michael--korsoutletonline.com/ michael kors outlet online
http://www.oakley--sunglass.com/ oakley sunglasses cheap
http://www.saclancelfrance.com/ sac lancel
http://www.katespade--outlet.com/ kate spade outlet
http://www.katespadeoutlet-online.com/ kate spade outlet online
http://www.katespade-online.com/ kate spade online
http://www.coachoutlet-onlinestore.com/ coach factory outlet
http://www.abercrombie-andfitch.com/ abercrombie and fitch
http://www.michaelkors-outletsonline.com/ michael kors outlet
http://www.sacportefeuille.com/ sac portefeuille
http://www.oakley-sunglassesoutlet.com/ oakley sunglasses outlet
http://www.michael--korsoutlet.com/ michael kors outlet
http://www.toryburch-outlet-online.com/ tory burch outlet online
http://www.abercrombieandfitchstore.com/ abercrombie & fitch
http://www.fit-flops.co.uk/ fitflops
http://www.coachoutlet-onlinefactory.com/ coach outlet online
http://www.coachfactoryoutlet-bag.com/ coach factory outlet
http://www.tory-burchshoes.com/ tory burch shoes
http://www.coachfactoryoutletclearance.com/ coach factory outlet
http://www.raybansunglasses-cheap.com/ cheap ray ban sunglasses
http://www.valentino.us.com/ valentino
http://www.fitfloponline.co.uk/ fitflop uk
http://www.coach-outletonlinefactory.com/ coach outlet
http://www.coachoutlet-factorystore.com/ coach outlet store online
http://www.air--jordans.com/ air jordan
http://www.timberlandshoesus.com/ timberland shoes
http://www.michaelkors--handbags.com/ michael kors handbags
http://www.coachfactoryoutletnew.com/ coach factory outlet
http://www.coachfactory-onlineoutlet.com/ coach factory outlet
http://www.truereligionbrandjeans.us.com/ true religion outlet
http://www.truereligionjeans.us.com/ true religion jeans
http://www.coach--handbags.com/ coach outlet online
http://www.louisvuitton--outlet.us/ louis vuitton outlet
http://www.timberland--shoes.com/ timberland boots
http://www.isabelmarantshoes.us.com/ isabel marant shoes
http://www.coachoutletonline-factory.com/ coach outlet online
http://www.michael-korsonlineoutlet.com/ michael kors outlet online
http://www.louisvuitton-handbag.us/ louis vuitton handbags
http://www.coach-outletstoreonline.com/ coach outlet store online
http://www.true-religion-jeans.com/ true religion jeans
http://www.coach-outletfactoryonline.com/ coach factory outlet online
http://www.coachfactoryoutlet-official.com/ coach factory outlet
http://www.louis-vuittonoutlets.com/ louis vuitton outlet
http://www.officialcoachonlinefactorysale.com/ official coach factory outlet
http://www.coachoutlet-storefactory.com/ coach outlet online
http://www.michael-korsoutletsonline.com/ michael kors outlet
http://www.tiffanysjewelry-co.com/ tiffany and co jewelry
http://www.celineoutlet-online.com/ celine outlet
http://www.celine-handbags.com/ celine handbags
http://www.toms--shoes.us/ toms shoes
http://www.fitflopsandalssale.com/ fitflops
http://www.fitflopusaonline.com/ fitflop outlet
http://www.prada-handbag.com/ prada handbags
http://www.tiffanyandcoinc.com/ tiffany jewelry
http://www.prada-outlets.com/ prada outlet
http://www.michael-korsoutletinc.com/ michael kors
http://www.marcjacobs.us.com/ marc jacobs
http://www.supra.us.com/ supra shoes
http://www.ralphlaurenpolo-inc.com/ polo ralph lauren
http://www.tiffanyjewelry.us.com/ tiffany jewelry

__________

Football Chaussures (http://www.chaussuresdefootclub.com) says:

2014-11-04 09:07:30

http://www.chaussuresdefootclub.com

__________

barbour uk (http://www.iimraipurconfluence.com) says:

2014-11-13 21:17:17

Of particular note is that Vanke,

__________

http://www.quelavenir.fr (http://www.quelavenir.fr) says:

2014-11-13 21:33:42

Of particular note is that Vanke,

__________

wlp (http://www) says:

2015-06-06 04:00:54

burberry outlet, http://www.burberry-outlet.jp.net/
burberry outlet online, http://www.burberryoutlet.org.uk/
burbery outlet store, http://www.burberryoutlet-online.co.com/
burberry outlet, http://www.burberryoutlet-online.in.net/
calvin kleins outlet, http://www.calvinklein.co.com/
celine bags, http://www.celinebags.org/
chanel bags, http://www.chanelhandbags.net.co/
softball bats, http://www.cheapbaseballbats.net/
christian louboutin outlet, http://www.christianlouboutinshoes.ar.com/
baseball jerseys, http://www.cheapjerseys.in.net/
air jordan shoes, http://www.cheap-jordans.net/
michael kors handbags clearance, http://www.cheapmichaelkors.us.org/
nike outlet, http://www.cheap-nikeshoes.com/
oakley sunglasses cheap, http://www.cheapoakley.us.org/
oakley outlet, http://www.cheapoakleysunglasses.co.com/
oakley sunglasses, http://www.cheap-oakleysunglasses.in.net/
ray bans, http://www.cheaprayban.com.co/
shoes outlet, http://www.cheapshoes.com.co/
ugg boots, http://www.cheapuggboots.eu.com/
flat iron, http://www.chiflatiron.net.co/
christian louboutin shoes, http://www.christian--louboutin.in.net/
louboutin, http://www.christianlouboutin.org.uk/
christian louboutin outlet, http://www.christianlouboutinshoes.jp.net/
burberry, http://burberry.outletnow.net/
christian louboutin shoes, http://christian.louboutin-outlet.net/
tory burch sale, http://toryburch.salesandals.net/
abercrombie kids, http://www.abercrombieand-fitch.com.co/
abercrombie, http://www.abercrombiefitch.us.com/
abercrombie and fitch, http://www.abercrombie-kids.us.com/

__________

Migukapy (http://orderlevi.com) says:

2017-10-20 14:33:09

Kamagra Sildenafil Citrate Acheter Cialis 20 Mg Cialis 5 Mg Erezione <a href=http://orderlevi.com>only here what is levitra</a> Onlinedrug

__________

ylq says:

2017-11-28 00:09:36

http://www.soccershoes-outlet.com/, http://www.mcm-backpacks.com.co/, http://www.raybans-glasses.com.co/, http://www.vans-shoesoutlet.co.uk/, http://www.salvatore-ferragamos.com/, http://www.nike-huarache.co.nl/, http://www.retrojordan-shoes.com/, http://www.christian-louboutinshoesoutlet.com/, http://www.michaelkors.co.nl/, http://www.north-face.com.co/, http://www.marc-jacobs.us.com/, http://www.rosherun-shoes.us/, http://www.ralphlauren-polos.com.co/, http://www.jeans-truereligion.com/, http://www.nikeshoes.de/, http://www.scarpe-hoganshoes.it/, http://www.louboutinshoes.jp.net/, http://www.montblancpences.com/, http://www.air-maxschoenen.co.nl/, http://www.christian-louboutin-shoes.com/, http://www.cheap-jerseys.com.co/, http://giants.nfl-jerseys.org/, http://www.jimmychoo-shoes.com/, http://pelicans.nba-jersey.com/, http://www.rayban-sunglasses.co/, http://www.newbalanceschuhe.com.de/, http://www.outlet-toryburch.com/, http://magic.nba-jersey.com/, http://www.ray-bans.net.co/, http://www.barboursjackets.com/, http://www.longchamps-bags.us.com/, http://www.kate-spadebags.com/, http://www.cheapomega-watches.com/, http://www.michael-korsbags.com.co/, http://www.mbt-outlet.com/, http://pistons.nba-jersey.com/, http://www.outlet-michaelkors.us.org/, http://www.polo-ralphlaurens.us.com/, http://www.oakleysunglasses-canada.ca/, http://www.chiflatironhair.us.com/, http://raiders.nfl-jerseys.org/, http://www.nikeair-max.ca/, http://www.woolrich-jackets.com/, http://www.truereligions.net/, http://www.nike-skos.com/, http://bills.nfl-jerseys.org/, http://www.watches-omega.com/, http://www.raybans-outlet.com.co/, http://www.thenorth-face.com.co/, http://www.nike-shoes.co.nl/, http://www.nike-shoesoutlet.co.uk/, http://www.michaelkors-ins.com/, http://www.jordan-retros.com/, http://www.oakleys-sunglasses.mex.com/, http://www.nba-shoes.com/, http://www.pradas.com.de/, http://www.salvatoreferragamo.us.com/, http://www.raybanoutlet.ca/, http://www.sunglasses-oakleys.com.co/, http://www.crystals-swarovskis.com/, http://www.birkenstocks.com.de/, http://jazz.nba-jersey.com/, http://www.michaels-korsoutlet.com/, http://www.nike-shoes.com.co/, http://www.nike-airmax.com.de/, http://www.nike-airmaxsc.co.uk/, http://www.christian-louboutin.jp.net/, http://www.burberry-storevip.com/, http://www.designer-handbags.com.co/, http://www.ralph-laurens-outlet.com/, http://www.oakleys.org.es/, http://www.skechers-shoesoutlet.com/, http://www.mcm-handbags.org/, http://www.valentino-shoesoutlet.us.com/, http://panthers.nfl-jerseys.org/, http://broncos.nfl-jerseys.org/, http://www.ferragamos.co.uk/, http://www.michael-kors.cc/, http://www.nike-shoesstore.com/, http://www.barbours.us.com/, http://www.basketballshoes.com.co/, http://www.outelt-ralphlauren.co.uk/, http://www.poloralphlauren.com.de/, http://rayban.black-friday.vip/, http://www.babylisspros.com/, http://www.supra-footwears.com/, http://www.converse-schuhe.com.de/, http://www.uhren-stores.de/, http://www.bottega-bags.com/, http://www.adidas-shoes.co.nl/, http://steelers.nfl-jerseys.org/, http://www.okglassesale.com/, http://www.lacosteoutlet.com.co/, http://www.jimmychoos-shoes.com/, http://www.nike-rosherun.com.es/, http://www.michaelkorsoutlet.se/, http://coach.euro-us.net/, http://www.polosoutlet-store.com/, http://www.new-balanceshoes.com/, http://www.outlet-toryburchshoes.com/, http://oakley.black-friday.vip/, http://www.outlet-rayban.co.uk/, http://www.outlet-burberry-bags.com/, http://www.cheap-raybansoutlet.com.co/, http://seahawks.nfl-jerseys.org/, http://nuggets.nba-jersey.com/, http://rockets.nba-jersey.com/, http://www.tommyhilfigers.co.nl/, http://www.raybans-outlet.cc/, http://www.hollister-clothings-store.com/, http://www.burberryoutletonline.com.de/, http://www.tommy-hilfigers.net.co/, http://hawks.nba-jersey.com/, http://www.jordan.com.de/, http://www.new-balanceoutlet.org/, http://www.outlet-michaelkors.com/, http://www.levis-jeansoutlet.com/, http://www.birkenstockshoes.com.de


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: