# netStream: Stop already!

**URL:** https://forum.kirupa.com/t/netstream-stop-already/279616
**Category:** Uncategorized
**Created:** [January 16, 2009, 3:48pm UTC](https://forum.kirupa.com/t/netstream-stop-already/279616 "2009-01-16T15:48:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![MadTurki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@MadTurki](https://forum.kirupa.com/u/MadTurki)
#### Post date: [January 16, 2009, 3:48pm UTC](https://forum.kirupa.com/t/netstream-stop-already/279616/1 "2009-01-16T15:48:57Z")

</div>

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:

```auto
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!

```auto
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);
    }
}

```
