Pass .Net type from one JS function to another...

So not sure what is up here. I am looking to pass an XML object that I created in one function to another function but am getting some weird errors.

My code (simplified) looks like this:

function handleContent(){
	
	var xml = new XmlDocument();
	xml.LoadXml(contentStr);
			
	if (xml.HasChildNodes){
		
		Debug.Log(xml.FirstChild.ChildNodes.Count);
		Debug.Log(xml.FirstChild.ChildNodes[0].OuterXml);
		xmlTest(xml);
	
	} else {
		Debug.Log("Not XML");
	}							
}

function xmlTest(xml){
	Debug.Log("TEST: " + xml.FirstChild.ChildNodes[0].OuterXml);
}

In the xmlTest function an error will occur that reads:

‘MissingFieldException: Cannot find variable ChildNodes’

Now the real fishy part is the two debug lines above the call to xmlTest work perfectly fine and note the second debug line in the handleContent function and the debug line in the xmlTest function are the same.

Anyone have any thoughts?

Thanks!

– Clint

Convert this:
function xmlTest(xml){

to this:
function xmlTest(xml : XmlDocument){

Then the compiler can resolve any errors at compile time (since it knows the type) and probably will give you a clearer error. It will also execute faster.

Thanks Joe!

Once I specified the ‘XmlDocument’ it worked as expected.

Regards,

– Clint