Index.base.net.byteLoader class Explanation:
Basic ability to load images by byte, SWF, etc.
Constructors
Public Function Byteloader (url:string = "")
If the parameter URL is passed in, the load is executed immediately!
Load Loading method
Public function Load (_url:string): void
Start loading, _url is loaded address
Updata Update Data method
Public Function Updata (): void
To update the read bytes of the buffer
Close Shutdown method
Public function Close (): void
Class to use, clear all useless data, can also be used to forcibly close the data flow, stop the download
Data property
public Var Data:bytearray
Returns the loaded bytes
URL Property
public Var url:string
Returns the loaded URL
Isload property (Read only)
Public function Get Isload (): Boolean
Returns whether there is data in the load
Progressevent.progress Events
Load in the process of scheduling, with loading conditions attached
Event.complete Events
Load Complete Schedule
Example:
Import Index.base.net.ByteLoader;
var bl:byteloader = new Byteloader;
Bl.load ("http://www.xiaos8.com/uploads/pro/50preso3a2.swf");
Bl.addeventlistener (Event.complete,completefun);
Bl.addeventlistener (Progressevent.progress,progressfun);
function Completefun (e:event): void{
var loader:loader = new Loader;
Loader.loadbytes (Bl.data);
AddChild (loader);
Bl.removeeventlistener (Event.complete,completefun);
Bl.removeeventlistener (Progressevent.progress,progressfun);
Bl.close ();
BL = null;
}
function Progressfun (e:progressevent): void{
Trace (e.bytesloaded);
If it is a JPEG image in progressive format, read the byte when the event is published, and load it with loader.loadbytes, it can form the edge load side display
}
Source:
Copy Code code as follows:
Package index.base.net{
Import Flash.events.EventDispatcher;
Import flash.events.ProgressEvent;
Import flash.events.Event;
Import Flash.utils.ByteArray;
Import Flash.net.URLStream;
Import Flash.net.URLRequest;
public class Byteloader extends eventdispatcher{
public Var url:string;
public Var Data:bytearray;
private Var Stream:urlstream;
Public Function Byteloader (url:string = "") {
if (URL!= "") {
Load (URL);
}
}
Load
Public function Load (_url:string): void{
url = _url;
data = new ByteArray;
stream = new Urlstream;
Stream.load (new URLRequest (URL));
Stream.addeventlistener (Event.complete,completefun);
Stream.addeventlistener (Progressevent.progress,progressfun);
}
In load
Private Function Progressfun (e:progressevent): void{
if (stream.bytesavailable = = 0) return;
Updata ();
Dispatchevent (e);
}
Load complete
Private Function Completefun (e:event): void{
Stream.removeeventlistener (Event.complete,completefun);
Stream.removeeventlistener (Progressevent.progress,progressfun);
Updata ();
if (isload) stream.close ();
Dispatchevent (e);
}
Update data
Public Function Updata (): void{
if (isload) stream.readbytes (data,data.length);
}
Purge data
Public function Close (): void{
if (isload) stream.close ();
stream = null;
data = null;
}
Gets whether there is data in the load
Public function Get Isload (): boolean{
if (stream = null) return false;
return stream.connected;
}
}
}