I’m trying to make a video player where it reads the videos from XML, creates thumbnails, you click the thumb it plays the video. The problem I have is that if you play one video, then the next, the first video keeps playing! I’ve made it try to detect if there are children and then if no children exist, proceed as normal. If a child already exists, close the stream, remove the child, start again. When I use ns.close(); I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mediagalleryv_fla::MainTimeline/playVideo()
at MethodInfo-481()
/wrists.
Here is my function where I’m trying to do this. I’m such a n00b I know there’s more errors in here. Much thanks for the help!
function playVideo(dataPath:String,desc:String):void {
trace("video clicked: " + dataPath);
if (vid_holder.numChildren > 1) {
trace("no children");
ns.close();
vid = null;
var vid:Video = new Video(480, 360);
vid_holder.addChild(vid);
vid.name="vid";
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play(dataPath);
} else {
trace("no children");
var vid:Video = new Video(480, 360);
vid_holder.addChild(vid);
vid.name="vid";
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play(dataPath);
}
}