import mx.utils.Delegate;
import mx.events.EventDispatcher;
class fc.load.AbstractLoad {
private var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
private var loadObject:Object;
private var loadID:Number;
function getBytesLoaded() {
return loadObject.getBytesLoaded();
}
function getBytesTotal() {
return loadObject.getBytesTotal();
}
private function checkProgress() {
var perLoaded:Number = Math.floor(getBytesLoaded()/getBytesTotal()*100);
dispatchEvent({type:"onProgress", value:perLoaded});
endLoad(perLoaded); }
private function startLoad() {
EventDispatcher.initialize(this);
loadID = setInterval(Delegate.create(this, checkProgress), 30);
dispatchEvent({type:"onProgress", value:0});
}
private function endLoad(perLoaded) {
if (perLoaded>=100) {
dispatchEvent({type:"onComplete", value:loadObject});
clearInterval(loadID);
} }
}
2、加载xml的类
import fc.load.AbstractLoad;
import mx.utils.Delegate;
class fc.load.Xml extends AbstractLoad {
private var loadObject:XML;
function Xml() {
loadObject = new XML();
loadObject.ignoreWhite = true;
System.useCodepage = true;
}
public function load(url:String) {
loadObject.load(url);
startLoad(); }
}
3、加载css的类
import fc.load.AbstractLoad;
import mx.utils.Delegate;
class fc.load.Css extends AbstractLoad {
private var loadObject:TextField.StyleSheet;
function Css() {
loadObject = new TextField.StyleSheet();
}
public function load(url:String) {
loadObject.load(url);
startLoad(); }
}
4、加载影片的类
import fc.load.AbstractLoad;
class fc.load.Movie extends AbstractLoad {
private var loadObject:MovieClip;
function Movie(mc) {
//装载影片等的影片剪辑
loadObject = mc;
}
public function load(url:String) {
loadObject.loadMovie(url);
startLoad(); }
public function unload() {
loadObject.unloadMovie();
}
}
5、编写loading类
class Loading {
var _path:MovieClip;
function Loading(p) {
_path = p; }
function create(value) {
_path.createTextField("loading", _path.getNextHighestDepth(), 0, 0, 0, 0);
_path.loading.autoSize = true;
_path.loading.text = "loading..."+value+"%";
_path.loading._x = (200-_path.loading._width)/2;
_path.loading._y = (233-_path.loading._height)/2;
} function clear() {
_path.loading.removeTextField();
}
}