I’m making the jump from AS2 to AS3 and I have a piece of code that I used in AS2 which I’m trying to translate to AS3. Basically what I want to do is check to see if the swf is already cached so that it skips the preloader. Here’s the AS2 code:
stop();
this.onEnterFrame = function() {
if (this.getBytesLoaded()>=this.getBytesTotal() && this.getBytesLoaded()>0) {
this.gotoAndStop(4);
delete this.onEnterFrame;
} else {
this.gotoAndStop(2);
delete this.onEnterFrame;
}
};
Also I got this code which loads and external swf and also unloads it when another swf is called (got it from another forum). I would like to do much the same thing, check if the external swf is cached and skip the preloader function and directly load the swf.
//preloader
var _swfLoader:Loader;
var _swfContent:MovieClip;
function loadSWF(path : String):void {
var _req : URLRequest = new URLRequest ();
_req.url = path;
_swfLoader = new Loader ();
setupListeners(_swfLoader.contentLoaderInfo);
_swfLoader.load(_req);
}
function setupListeners(dispatcher : IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, addSWF);
dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
}
function preloadSWF(event : ProgressEvent):void {
var _perc : int = (event.bytesLoaded / event.bytesTotal) * 100;
percentTxt.text = _perc + "%";
progress_mc.gotoAndStop(_perc );
}
function addSWF(event : Event):void {
event.target.removeEventListener(Event.COMPLETE, addSWF);
event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
trace("Load Complete");
this.percentTxt.visible = false;
this.progress_mc.visible = false;
_swfContent = event.target.content;
this.addEventListener("close", unloadSWF);
extContainer.addChild(_swfContent);
}
function unloadSWF(event : Event):void {
_swfLoader.unloadAndStop();
extContainer.removeChild(_swfContent);
extContainer._swfContent = null;
}
I haven’t’ got a handle of how to write functions in AS3 yet so if there’s a helpful soul out there who can help, I’ll be very grateful
Cheers,