Access to member function?

Hi,
i wrote two scripts in Javascript where i want to call a functin of the seconds class. But i gets the following message:

Here´s my code:
Main.js

private var stream : StreamAssetBundle;

function OnGUI()
{
	if (GUILayout.Button("... start DL" )){
		stream.StartDownload();
	}
}

StreamAssetBundle.js

class StreamAssetBundle{
	public function StartDownload () {
		print("Start" );
	}
}

So where´s my error?Thanks

Are you sure you have initialised the stream variable somewhere? There isn’t any constructor call in the code you’ve posted.

You may consider creating a static function.

Thanks for your hints but it doesn´t work.
My code is that:

class StreamAssetBundle{
	public function StreamAssetBundle () {
		print("StreamAssetBundle" );
	}
	static public function StartDownload () {
		print("Start" );
	}
}

Maybe someone could check it. Would be nice. Thanks a lot.

Like Andeeeeeeeeeee said, you don’t seem to have initialized the “stream” variable. You’ve declared it, but done nothing else, hence it is null. Unless there’s more code you haven’t shown.

–Eric

I´ve tested already like this but no debug-prints…

function OnGUI()
{
	if (GUILayout.Button("... start DL" )){
		var stream : StreamAssetBundle= new StreamAssetBundle();
		stream.StartDownload();
	}
}

new xxx() can not be used for MonoBehaviours

Can you please write me how to initilize it correctly? I wrote it without the new-operator, but didn´t help…

that should work

function OnGUI() 
{ 
   if (GUILayout.Button("... start DL" )){ 
      var stream : StreamAssetBundle= gameObject.AddComponent(StreamAssetBundle) as  StreamAssetBundle; 
      stream.StartDownload(); 
   } 
}

Oh yeah. Nice. It works. Thanks a lot for your time.
Have a nice weekend.
yosh