ActionScript 3 Tutorial – A Better Preloader

Author : Craig

Author's Website | Articles from

Having problems with your preloader? It's to be expected. Preloaders have a history of causing a lot of grief among Flash designers. Even once you get the loader bar working, you'll often find that it takes the preloader itself several seconds before it shows up. Which defeats the purpose of having a preloader in the first place. So you dive in deeper and quickly discover that there are a dozen tweaks that have to be made just to get your preloader to show up quicker.

In today's free ActionScript tutorial, you'll learn a better way to create preloaders--a way that doesn't require a bunch of workarounds to get it functioning properly! Enjoy!

Here's the code from the tutorial:

myLoader.addEventListener(Event.COMPLETE, onComplete);
myLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);
 
function onProgress(e:ProgressEvent):void
{
	var pct:Number = e.bytesLoaded / e.bytesTotal;
	preloader_mc.bar_mc.scaleX = pct;
}
 
function onComplete(e:Event):void
{
	preloader_mc.x = -1000;
}
 
myLoader.load(new URLRequest("berries.swf"));

Like this post? Share it!

  • Tweet
  • Facebook
  • Diggit
  • Delicious
  • Diggit
  • Diggit
  • Diggit
  • Diggit
  • Diggit

Related Posts


User Comments


  1. MsJudyK
    October 22, 2009

    Is there a way to change the download settings in CS3 to test with a simulation? Unfortunately, I don’t have CS4.

    Reply

  2. 3d tutorials
    January 9, 2010

    Thanks a lot for such important source code. It’s really helpful and needed.

    Reply

  3. PEpe
    April 6, 2010

    Hi before anything, thanks or the post it’s really useful.
    But i have a problem with your code, personally im loading the swf of the same site on the web, and it marks aproblem of a Sandbox. I have tried to allow the domain security and it still dosent work.

    Maybe you know whats the problem.Thanks for the help, this is the code.

    stage.displayState = StageDisplayState.FULL_SCREEN;

    myLoader.load(new URLRequest(“http://devocionpreciosisimasangre.com/contenido.swf”));
    myLoader.addEventListener(Event.COMPLETE, onComplete);
    myLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);
    Security.allowDomain(“http://devocionpreciosisimasangre.com/”);
    Security.allowInsecureDomain(“http://devocionpreciosisimasangre.com/”);
    Security.LOCAL_TRUSTED;

    function onProgress(e:ProgressEvent):void
    {
    var pct:Number = e.bytesLoaded / e.bytesTotal;
    preloader_mc.bar_mc.scaleX = pct;
    }

    function onComplete(e:Event):void
    {
    preloader_mc.x = -1000;
    }

    Reply

  4. PEpe
    April 6, 2010

    Sorry the code i posted is another i tried, where i put the swf on another site so i dosent make the same problem, but still isn’t working.

    Thanks

    Reply

  5. Ron
    April 14, 2010

    My problem is the movie starts to play before the preloader finishes loading. Please help :(

    Reply

  6. Jim
    May 4, 2010

    Your code only works with SWFs that load an image. Anything other than a graphic on the stage the SWF appears before/while the progress bar is visible and loading.

    Reply

  7. Jeepee
    June 17, 2010

    hello. great tutorials. you are one of the rares who really explain what each code does. btw can u make tutorial how to make grow game kind game? http://www.eyezmaze.com/grow/cube/

    Reply

  8. Sheryl
    July 6, 2011

    Dear Mr. Campbell, Back when Flash was AS2, you had a tutorial about how to get rid of the flash of white before Flash loads. You suggested using the html code generated during the publish step in place of the code inserted using Dreamweaver’s insert function. It worked great. I have found that I can still do that, but because there is now a lot more code that goes along with the Dreamweaver insert function, I wonder if removing all the insert function code will bite me in the end. Using suggestions by other Flash programmers who are not at your level has been a disaster. The embed source code () to get rid of the flash of white works in IE but not in Chrome or Firefox. Thank you for all the tutorials you’ve produced over the years. They have helped me more than I could ever tell you.

    Reply

  9. ajishiteru
    October 10, 2011

    Thanks for sharing. It really work for me.
    I really appreciate it. I just modified the barmc into scale Y.

    Reply

Leave a Reply

 
  Twitter Followers

Stock Flash Files Web Development Tutorials

Stock Graphics Video Files


Your Ad Here