我是個小白,我想在類里加載一個外部視頻,遇到了以下問題:
ap.as的代碼如下:
package test {
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.display.Sprite;
import flash.events.Event
public class sp extends Sprite {
var theVideo: Video; //視頻物件
var theNet: NetConnection; //連接物件
var theNets: NetStream; //資料流物件
public function sp() {
}
public function InitVars(): void {
var theVideo = new Sprite ();
theVideo = new Video(1920, 1080);
theVideo.x = theVideo.y = 0;
addChild(theVideo);
theNet = new NetConnection();
theNet.connect(null);
theNets = new NetStream(theNet);
theNets.client = this;
theVideo.attachNetStream(theNets);
}
public function LoadMovie(): void {
theNets.play("裝飾畫總.mp4");
theNets.addEventListener(NetStatusEvent.NET_STATUS, onStatusHandler);
}
public function onStatusHandler(e: NetStatusEvent): void {
var evtCode: String = e.info.code;
switch (evtCode) {
case "NetStream.Play.Start":
break;
case "NetStream.Play.Empty":
break;
case "NetStream.Play.Full":
break;
case "NetStream.Play.StreamNotFound":
break;
case "NetStream.Play.Stop":
RemoveVedio();
break;
}
}
//卸載視頻
public function RemoveVedio(): void {
theNets.pause();
theNets.dispose();
theNet = null;
theVideo.clear();
removeChild(theVideo);
}
}
}
fla里的代碼如下:
import test.sp;
var onesp:sp=new sp();
onesp.LoadMovie();
onesp.InitVars();
運行的時候輸出面板里顯示如下:
TypeError: Error #1009: 無法訪問空物件參考的屬性或方法。
at test::sp/LoadMovie()
at 視頻檔案2_fla::MainTimeline/frame1()
uj5u.com熱心網友回復:


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/102333.html
標籤:其他開發語言
下一篇:爬蟲url出錯
