Interface org.as2lib.io.file.File

org.as2lib.core.BasicInterface
   +--org.as2lib.io.file.File

Description

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!"); } }

Method Index

addListener(), countLines(), exists(), getBytesLoaded(), getBytesTotal(), getContent(), getLine(), getLocation(), isLoaded(), isLoading(), load()

Inherited from BasicInterface

toString()

Method Detail

load

public function load(location:String):Void

Loads a file from a location. This method is similar to the MovieClip.load method.

Parameters

locationLocation (URL) to of the file to load.

isLoaded

public function isLoaded(Void):Boolean

Boolean flag if the file is loaded.

Return

true if the file is loaded. false if the file is loading or .load wasn't called.

isLoading

public function isLoading(Void):Boolean

Boolean flag if the file is loading.

Return

true if the file is loading. false if the file is already loaded or .load wasn't called.

exists

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.

Return

true if the file exists.

Throws

FileNotLoadedExceptionIf nothing has been loaded before.

getContent

public function getContent(Void):String

Getter for the content of the complete file.

Return

Content of the file.

getLine

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.

Parameters

lineLine to get the content of (starting with 0).

Return

Content of the line.

countLines

public function countLines(Void):Number

Returns the amount of lines in the content.

Return

Amount of lines within the content.

getLocation

public function getLocation(Void):String

Location of the File.

Return

The location of the file as loaded with load.

getBytesLoaded

public function getBytesLoaded(Void):Number

Getter for the bytes that has been loaded already. It will return 0 if no bytes have been loaded.

Return

Amount of bytes that has been loaded.

getBytesTotal

public function getBytesTotal(Void):Number

Getter for the total filesize in bytes.

Return

Total size of the file in bytes.

addListener

public function addListener(listener:FileListener):Void

Adds a listener to the file for all events published by the file.

Parameters