# Accessing constructor variable from a function?

**URL:** <https://forum.kirupa.com/t/accessing-constructor-variable-from-a-function/266696>\
**Category:** flash\
**Created:** [July 23, 2008, 3:30pm UTC](https://forum.kirupa.com/t/accessing-constructor-variable-from-a-function/266696 "2008-07-23T15:30:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cine](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Cine](https://forum.kirupa.com/u/Cine)\
**Post date:** [July 23, 2008, 3:30pm UTC](https://forum.kirupa.com/t/accessing-constructor-variable-from-a-function/266696/1 "2008-07-23T15:30:31Z")

</div>

So, I’m trying to write a generic video player in AS3. I actually had it working perfectly when writing it on the stage in a frame. (so much easier!) Then I decided to convert it to a document class, that being a better coding practice and all.

My main issue now is this part in the constructor:

```auto
		// Create net connection and stream.
			var conn:NetConnection = new NetConnection();
			conn.connect(null);
			
			var stream:NetStream = new NetStream(conn);
			stream.play(mfile);
			
			var metaListener:Object = new Object();
			metaListener.onMetaData = theMeta;
			stream.client = metaListener;

			// Sound
			var st:SoundTransform = new SoundTransform();
			stream.soundTransform = st;

			// Video
			var video:Video = new Video();
			video.attachNetStream(stream);

```

This is followed by a bunch of eventListeners. Several functions called by the eventListeners reference conn, stream and str, so the result is a whole bunch of **1120: Access of undefined property conn.** errors. This is where I need the variables to go global.

I did attempt to move the variables above out of the function, but that gave me the following output, which leaves me even more lost.

**TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at src.videoPlayer::videoPlayer()**

Any help is deeply appreciated!
