# Video class and close()?

**URL:** <https://forum.kirupa.com/t/video-class-and-close/289038>\
**Category:** Uncategorized\
**Created:** [May 25, 2009, 2:37pm UTC](https://forum.kirupa.com/t/video-class-and-close/289038 "2009-05-25T14:37:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brndn](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@brndn](https://forum.kirupa.com/u/brndn)\
**Post date:** [May 25, 2009, 2:37pm UTC](https://forum.kirupa.com/t/video-class-and-close/289038/1 "2009-05-25T14:37:39Z")

</div>

Hi there  
I have implimented a video handler class to part of my project. What it is intended to do is remove the playing video using the netStream method and create a new instance with a new video file.  
I can remove it using a standard removeChild function. However the pain occcurs when I can still hear the audio palying.

I guess my issue is that this is handled in a class and every time I create a new video it creates a new instance of the class.

My question is then how do I call netStram.close() from another class before creating a new video instance.

Here is the guts of my code if anyone could help.

\*\*linked class for a gallery displayer  
[AS]function on\_Press(e:MouseEvent):void {

```
var my_thumb:Loader = Loader (e.target);
my_thumb.alpha = 1;
if(clicks &gt; 0){
		removeChild( videoContainer )
}
videoContainer = new MovieClip ;
addChild( videoContainer )

getVideo = new videoLoader("redbelt.flv");

```

videoContainer.addChild( getVideo );  
videoContainer.x = Number(my\_thumb.name)\*100;  
clicks ++;  
}

[/AS]

\*\*videoLoader Class  
[AS] package com.myVideo{

import flash.display.Sprite;  
import com.myVideo.simpleFlv;  
public class videoLoader extends Sprite {  
var v:simpleFlv = new simpleFlv();

public function videoLoader(callTarget:String) {

```
		v.playMyFlv(callTarget);
		
		addChild(v);

```

}  
private function removeVideo():void{  
v.playMyFlv.closeMyFlv();  
trace(“remove”);  
}

```
}

```

}[/AS]

\*\*simpleFlv Class  
[AS]package com.myVideo{  
import flash.display.Sprite;  
import flash.net.NetConnection;  
import flash.net.NetStream;  
import flash.media.Video;  
import flash.text.TextFieldAutoSize;  
import flash.text.TextField;  
import flash.events.Event;  
import flash.events.TimerEvent;  
import flash.events.NetStatusEvent;  
import flash.utils.Timer;

```
public class simpleFlv extends Sprite{
	public var _video:Video;
	public var _stream:NetStream;	
	public var _playbackTime:TextField;
	public var _duration:uint;
	public var _timer:Timer;
	
	public function simpleFlv(){
		_duration = 0;
		
		_playbackTime = new TextField();
		_playbackTime.autoSize = TextFieldAutoSize.LEFT;
		_playbackTime.y = 20;
		_playbackTime.x = 20;
		_playbackTime.text = "Buffering …";
		
		_timer = new Timer(1000);
		_timer.addEventListener(TimerEvent.TIMER, onTimer);
		_timer.start();
	}
	
	public function playMyFlv(flvUrl){
		_video = new Video();
		
		var connection:NetConnection = new NetConnection();
		connection.connect(null);
		
		_stream = new NetStream(connection);
		_stream.play(flvUrl);
		
		var Client:Object = new Object();
		Client.onMetaData = onMetaData;
		_stream.client = Client;
		_video.attachNetStream(_stream);
		
		_stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
		
		addChild(_video);
		//addChild(_playbackTime);
	}
	
	public function closeMyFlv(){
		_stream.close();
	}
	
	private function onMetaData(data:Object){
		_duration = data.duration;
	}
	
	private function onNetStatus(e:NetStatusEvent){
		_video.width = _video.videoWidth;
		_video.height = _video.videoHeight;
	}
	
	private function onTimer(t:TimerEvent){
		if( _duration &gt; 0 && _stream.time &gt; 0 ){
			_playbackTime.text = Math.round(_stream.time) + " / " + Math.round(_duration);
		}
	}
}

```

}[/AS]
