Menu Riverview Church

LOAD

Loaded assets are assets (images, sound, ...) separate from the application.

These assets are loaded after the application is loaded. Because they are loaded after the application is loaded, the application has a smaller file size.

EXAMPLE

Load

CODE

´╗┐package
{
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.net.URLRequest;

    public class ActionScriptLoad extends Sprite
    {
        public function ActionScriptLoad()
        {
            var url     :String     = "HappyFace.jpg";
            var request :URLRequest = new URLRequest(url);
            var loader :Loader     = new Loader();

            loader.load(request);
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleError);
        }

        private function handleProgress(e:ProgressEvent):void
        {
            var loaded :Number = e.target.bytesLoaded;
            var total :Number = e.target.bytesTotal;

            trace("Progress: " + String(Math.round((loaded / total) * 100)) + "%");
        }

        private function handleComplete(e:Event):void
        {
            var loader :Loader = Loader(e.target.loader);
            var bitmap :Bitmap = Bitmap(loader.content);

            addChild(bitmap);
            trace("Complete");
        }

        private function handleError(e:IOErrorEvent):void
        {
            trace("Error: Not Loaded");
        }
    }
}

Download