AS3 from writing class to organize notes: Byteloader class _flash AS3

Source: Internet
Author: User
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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.