Use the video, netconnection, and netstream classes to load and play FLV files. Process the corresponding event in the script:
Netstatusevent-when the netconnection object executes the connect () method, netstatus is changed. When the netstream object executes the play () method, error handling is also monitored by it.
The securityerrorevent-netconnection object executes the listener for a connect () error.
Listener for an error occurred when the asyncerrorevent-netstream object executes play.
Demo:
Package {
Import flash. display. Sprite;
Import flash. Events .*;
Import flash. Media. video;
Import flash.net. netconnection;
Import flash.net. netstream;
Public class netstatuseventexample extends sprite {
Private var videourl: String = "video. FLV ";
Private var connection: netconnection;
Private var stream: netstream;
Public Function netstatuseventexample (){
Connection = new netconnection ();
Connection. addeventlistener (netstatusevent. net_status, netstatushandler );
Connection. addeventlistener (securityerrorevent. security_error, securityerrorhandler );
Connection. Connect (null );
}
Private function netstatushandler (Event: netstatusevent): void {
Switch (event.info. Code ){
Case "netconnection. Connect. Success ":
Connectstream ();
Break;
Case "netstream. Play. streamnotfound ":
Trace ("unable to locate video:" + videourl );
Break;
}
}
Private function connectstream (): void {
VaR stream: netstream = new netstream (connection );
Stream. addeventlistener (netstatusevent. net_status, netstatushandler );
Stream. addeventlistener (asyncerrorevent. async_error, asyncerrorhandler );
VaR video: Video = new video ();
Video. attachnetstream (Stream );
Stream. Play (videourl );
Addchild (video );
}
Private function securityerrorhandler (Event: securityerrorevent): void {
Trace ("securityerrorhandler:" + Event );
}
Private function asyncerrorhandler (Event: asyncerrorevent): void {
// Ignore asyncerrorevent events.
}
}
}