How to Make a Efficient Flash AS3 SWF content Loader[Preloader]


Very effi­cient Loader Cod­ing Tutorial

the code using here is very clean , sim­ple and error less . you can load exter­nal swf file and call func­tion in that swf file


step 1 : Cre­ate Loader.fla and LoaderClass.as

open Loader.fla go to prop­er­ties type “Load­er­Class” class : filed under PUBLISH tab

image1

step 2 : Make a pre­loader movie

click on rec­tan­gle tool or ®

image2

then draw a reac­t­an­gle width : 300px & height :10px , color :#63F262

image3

after that right click on the rec­tan­gle and con­vert to sym­bol, when con­vert to sym­bol win­dow popup type the (1)Name : mc , (2)Type : Movie Clip , (3)Registeration : Left-center

image6

then name the Movi­Clip “mc” on prop­er­ties tab image7

again right click on the rec­tan­gle and con­vert to sym­bol, when con­vert to sym­bol win­dow popup type the (1)Name : preloader_mc , (2)Type : Movie Clip , (3)Registeration : cen­ter , (4)tick Export for Action­Script under Link­age tab

image5

dou­ble click on the preloader_mc and cre­ate a dynamic text field and name “percent_txt”

image8

image9

then click on Char­ac­ter Embed­ding and in the include these char­ac­ters: type “0123456789%”

image10

it will look like this

image10.5

step 3: Make Pre­loader Animation

dou­ble click on the preloader_mc and insert a frame at 100

image11

then cre­ate a motion tween on “mc” rec­tan­gle

image12insert a scale KeyFrame at 100th frame

image13

set width = 1 at first Frame

image14

come to root of the Scene delete the preloader_mc Movie Clip

and save your file

step 4: Write Pre­loader Class

open LoaderClass.as

?View Code ACTIONSCRIPT
package {
 
	//import needed classes
 
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
 
	dynamic public class LoaderClass extends MovieClip // main class
	{
 
		//declare private variables
 
		private var PRELOADER:preloader_mc= new preloader_mc();
		private var URL_:URLRequest;
		private var OBJLoader:Loader;
		private var isLoaded:Boolean;
		private var TOTAL_:Number;
		private var LOADED_:Number;
		private var isLoadedInited:Boolean;
 
		public function LoaderClass() {//main function
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			init();
		}
 
		public function init():void {
			PRELOADER.x = stage.stageWidth / 2;
			PRELOADER.y = stage.stageHeight / 2;
			addChild(PRELOADER);
			LoadContent(null);
			stage.addEventListener(Event.RESIZE,onResize);
		}
 
		public function LoadContent(URLReq:URLRequest) {
			if (URLReq == null) {
				URL_ = new URLRequest("swfContent.swf");
			} else {
				URL_ = URLReq;
			}
			OBJLoader = new Loader();
			OBJLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
			OBJLoader.load(URL_);
			addChild(OBJLoader);
			addEventListener(Event.ENTER_FRAME, onLoading);
		}
		public function loaded(param1:Event):void {
			isLoaded = true;
			return;
		}
		public function onLoading(e:Event) {
			TOTAL_ = OBJLoader.contentLoaderInfo.bytesTotal;
			LOADED_ = OBJLoader.contentLoaderInfo.bytesLoaded;
			var percent:Number = int(LOADED_ / TOTAL_ * 100);
			PRELOADER.gotoAndStop(percent);
			PRELOADER.percent_txt.text = percent + "%";
			if (! isLoadedInited && isLoaded) {
				isLoadedInited = true;
				var LoaderData:* = OBJLoader.content;
				LoaderData["loadData"](this);
			}
			if (TOTAL_ / LOADED_ == 1) {
				removeEventListener(Event.ENTER_FRAME,onLoading);
				removeChild(PRELOADER);
				stage.removeEventListener(Event.RESIZE,onResize);
				trace("content Loaded");
			}
 
			return;
		}
 
		public function onResize(e:Event) {
 
			PRELOADER.x = stage.stageWidth / 2;
			PRELOADER.y = stage.stageHeight / 2;
 
		}
 
	}
 
}

Source File :AS3 SWF Content Loading method-Source (71)

Bookmark and Share
VN:F [1.8.1_1037]
Rat­ing: 10.0/10 (1 vote cast)
VN:F [1.8.1_1037]
Rat­ing: +1 (from 1 vote)
How to Make a Effi­cient Flash AS3 SWF con­tent Loader[Preloader]10.0101

, , , , , , ,

  1. #1 by vijay on September 15th, 2009

    hi.….….….….….!

    UN:F [1.8.1_1037]
    Rat­ing: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rat­ing: 0 (from 0 votes)
(will not be published)