Very efficient Loader Coding Tutorial
the code using here is very clean , simple and error less . you can load external swf file and call function in that swf file
step 1 : Create Loader.fla and LoaderClass.as
open Loader.fla go to properties type “LoaderClass” class : filed under PUBLISH tab
step 2 : Make a preloader movie
click on rectangle tool or ®
then draw a reactangle width : 300px & height :10px , color :#63F262
after that right click on the rectangle and convert to symbol, when convert to symbol window popup type the (1)Name : mc , (2)Type : Movie Clip , (3)Registeration : Left-center
then name the MoviClip “mc” on properties tab
again right click on the rectangle and convert to symbol, when convert to symbol window popup type the (1)Name : preloader_mc , (2)Type : Movie Clip , (3)Registeration : center , (4)tick Export for ActionScript under Linkage tab
double click on the preloader_mc and create a dynamic text field and name “percent_txt”
then click on Character Embedding and in the include these characters: type “0123456789%”
it will look like this
step 3: Make Preloader Animation
double click on the preloader_mc and insert a frame at 100
then create a motion tween on “mc” rectangle
insert a scale KeyFrame at 100th frame
set width = 1 at first Frame
come to root of the Scene delete the preloader_mc Movie Clip
and save your file
step 4: Write Preloader Class
open LoaderClass.as
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)












































#1 by vijay on September 15th, 2009
hi.….….….….….!