org.as2lib.core.BasicInterface +--org.as2lib.io.file.File
Definition for a file with a loading delay.
Almost general definition for a file used in flash. It supports loading and response events.
Example:
import org.as2lib.io.file.FileListener;
import org.as2lib.io.file.SimpleFile; // Standard Implementation for a file.
class MyClass implements FileListener {
public function MyClass() {
var file:File = new SimpleFile(); // Choose your implementation.
file.addListener(this); // Add the instance as listener.
file.load("MyFile.txt"); // Load the source file.
}
public function onLoad(fileInfo:FileEventInfo):Void {
trace("I have loaded my file!");
trace("Content of the file: "+fileInfo.getFile().getContent());
trace("Content of line 2: "+fileInfo.getFile().getLine(1));
}
public function onProgress(fileInfo:FileEventInfo):Void {
trace("I am loading my file: "+fileInfo.getFile().getBytesLoaded());
}
public function onFileNotFound(fileInfo:FileEventInfo):Void {
trace("I havn't found my file!");
}
}
public function load(location:String):Void
Loads a file from a location. This method is similar to the MovieClip.load method.
location | Location (URL) to of the file to load. |
public function isLoaded(Void):Boolean
Boolean flag if the file is loaded.
true if the file is loaded. false if the file is loading or .load wasn't called.
public function isLoading(Void):Boolean
Boolean flag if the file is loading.
true if the file is loading. false if the file is already loaded or .load wasn't called.
public function exists(Void):Boolean
Boolean flag if the file exists. Note: Flash has usually some kind of delay with this method that has to be recognized by its implementation.
true if the file exists.
FileNotLoadedException | If nothing has been loaded before. |
public function getContent(Void):String
Getter for the content of the complete file.
Content of the file.
public function getLine(line:Number):String
Getter for the content in the specific line of the content. It will return "undefined" if the line doesn't exist. The line will not contain the linebreak.
line | Line to get the content of (starting with 0). |
Content of the line.
public function countLines(Void):Number
Returns the amount of lines in the content.
Amount of lines within the content.
public function getLocation(Void):String
Location of the File.
The location of the file as loaded with load.
public function getBytesLoaded(Void):Number
Getter for the bytes that has been loaded already. It will return 0 if no bytes have been loaded.
Amount of bytes that has been loaded.
public function getBytesTotal(Void):Number
Getter for the total filesize in bytes.
Total size of the file in bytes.
public function addListener(listener:FileListener):Void
Adds a listener to the file for all events published by the file.