SwfLoader
is a implementation of FileLoader to load
files with loadMovie
(usually .swf
files}.
Any content to be loaded with can be load with
SwfLoader
to a concrete MovieClip
instance that has to be
passed-in with the constructor.
SwfLoader
represents the time consuming part of accessing external
.swf
' ( SwfFile
is the handleable part} and therefore
contains a event system to add listeners to listen to the concrete events.
It is possible to add listeners using addListener
.
Example listener:
import org.as2lib.io.file.AbstractFileLoader;
import org.as2lib.io.file.LoadProgressListener;
import org.as2lib.io.file.LoadStartListener;
import org.as2lib.io.file.LoadCompleteListener;
import org.as2lib.io.file.LoadErrorListener;
import org.as2lib.io.file.FileLoader;
import org.as2lib.io.file.SwfFile;
class MySwfListener implements
LoadProgressListener, LoadStartListener,
LoadCompleteListener, LoadErrorListener {
public function onLoadComplete(fileLoader:FileLoader):Void {
var swf:SwfFile = SwfFile(fileLoader.getFile());
if (swf != null) {
// Proper swf available
} else {
// Wrong event handled
}
}
public function onLoadError(fileLoader:FileLoader, errorCode:String, error):Void {
if (errorCode == AbstractFileLoader.FILE_NOT_FOUND) {
var notExistantUrl = error;
// Use that url
}
}
public function onLoadStart(fileLoader:FileLoader) {
// show that this file just gets loaded
}
public function onLoadProgress(fileLoader:FileLoader) {
// update the percentage display with fileLoader.getPercentage();
}
}
Example of the usage:
import org.as2lib.io.file.SwfLoader;
var swfLoader:SwfLoader = new SwfLoader();
swfLoader.addListener(new MySwfListener());
swfLoader.load("test.swf");
new SwfFileLoader()
public function load(uri:String, method:String, parameters:Map, callBack:Executable):Void
Loads a certain .swf
by a http request.
It sends http request by using the passed-in uri
, method
and parameters
with .loadMovie
.
If you only need to listen if the SwfFile
finished loading
you can apply a callBack
that gets called if the File
is loaded.
uri | location of the file to load |
method | (optional) POST/GET as method for submitting the parameters,
default method used if method was not passed-in is POST.
|
parameters | (optional) parameters for loading the file |
callBack | (optional) Executable to be executed after the the file was loaded. |
load() in org.as2lib.io.file.FileLoader
public function getFile(Void):File
Returns the loaded file.
file that has been loaded
FileNotLoadedException | if the file has not been loaded yet |
getFile() in org.as2lib.io.file.FileLoader
public function getBytesLoaded(Void):Byte
Returns the total amount of bytes that has been loaded.
Returns null
if its not possible to get the loaded bytes.
amount of bytes that has been loaded
getBytesLoaded() in org.as2lib.io.file.FileLoader
public function getBytesTotal(Void):Byte
Returns the total amount of bytes that will approximately be loaded.
Returns null
if its not possible to get the total amount of bytes.
amount of bytes to load
getBytesTotal() in org.as2lib.io.file.FileLoader
public function onFrameImpulse(impulse:FrameImpulse):Void
Handles a frame
execution.
Helper that checks every frame if the .swf
finished loading.
impulse | FrameImpulse that sent the event
|
onFrameImpulse() in org.as2lib.env.event.impulse.FrameImpulseListener