Index.base.net. byteloader class description:
Basic functions: loading images and SwF by byte
Constructor
Public Function byteloader (URL: String = "")
If the parameter URL is input, load it immediately!
Load Method
Public Function load (_ URL: string): void
Start loading. _ URL is the loading address.
Updata data update Method
Public Function updata (): void
Updates the readable bytes of the buffer.
Close Method
Public Function close (): void
Class, clear all useless data, can also be used to forcibly disable data streams, stop download
Data attributes
Public var data: bytearray
Returns the loaded bytes.
URL attributes
Public var URL: String
Returns the loaded URL.
Isload attribute (read-only)
Public Function get isload (): Boolean
Whether data is being loaded
Progressevent. Progress event
Scheduling during loading with loading
Event. Complete Event
Load finished Scheduling
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 the JPEG image is in progressive format, read the byte when this event is published and load it with loader. loadbytes to form an edge loading and display.
}
Source code:
CopyCode The Code is 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 );
}
// Loading
Private function progressfun (E: progressevent): void {
If (stream. bytesavailable = 0) return;
Updata ();
Dispatchevent (E );
}
// Loading completed
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 );
}
// Clear data
Public Function close (): void {
If (isload) stream. Close ();
Stream = NULL;
Data = NULL;
}
// Obtain whether data is being loaded
Public Function get isload (): Boolean {
If (Stream = NULL) return false;
Return stream. connected;
}
}
}