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 (110)












































#1 by vijay on September 15, 2009 - 4:25 AM
hi.….….….….….!
#2 by did_ro on July 6, 2010 - 6:03 AM
Hi, this component looks amazing, but can I use it with flash CS4 in an AIR project ? Actually I didn’t managed to use it, but this could be because I don’t have enough skills to do so.
So is this possible ? How ?
Thanks in advance for any reply.
#3 by did_ro on July 6, 2010 - 6:14 AM
Hi, this Date Picker component looks amazing, but can I use it with flash CS4 in an AIR project ? Actually I didn’t managed to use it, but this could be because I don’t have enough skills to do so. Thanks in advance for any help.
#4 by NiDiN on July 11, 2010 - 3:10 AM
check this post for setup swc files in flash ide http://www.infogroupindia.com/blog/?p=513
and download swc file from download section
#5 by NiDiN on July 6, 2010 - 10:05 AM
yes you can, use swc in your project
#6 by poruntong on July 10, 2010 - 10:03 AM
how can I use th ecomponent with CS3 IDE
#7 by NiDiN on July 11, 2010 - 3:06 AM
HI,
check this post for setup swc files in flash ide http://www.infogroupindia.com/blog/?p=513
and download swc file from download section