Skip to content


[AS 3] Preloader -> flash.display.Loader and flash.display.LoaderInfo

Package is flash.display and the public class Loader

The Loader class is used to load SWF, JPG, PNG, or GIF files and uses the load method to initiate loading.

I have been searching around for some AS 3 preloader code and have come up with this.. but for some reason I just can’t get it to work.. any ideas?

Update:
http://manewc.com/2008/01/08/as-3-update-preloader-flashdisplayloader-and-flashdisplayloaderinfo/

package
{
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.ProgressEvent;

	public class Loader extends Sprite {

		private var ldr:Loader = new Loader();

	 	var req:URLRequest = new URLRequest("logo.gif");

	 	ldr.load(req);

	 	ldr.contentLoaderInfo.addEventListener(Event.OPEN,open);
		ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progress);
		ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,result);

		function open(evt:Event):void
		{
			trace ("opening file");
		}

		function progress(evt:ProgressEvent):void
		{
			trace ("loaded: " + evt.bytesLoaded);
		}

		function result(evt:Event):void
		{
			addChild(ldr);
		}
	 }
}

Posted in Actionscript 3, Preloading.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. just browsing says

    there may be an issue with using Loader as the class name.. maybe you should try

    public class LoaderScript extends Sprite



Some HTML is OK

or, reply to this post via trackback.