I'm trying to set a JSON object from a Javascript function and use it as parameter in another function, but this obj has no value outside the function. I created this json object outside the function:
var obj = {"Level":0, "Index":0, "Count":0, "AABB":[], "Point":[], "Children":[]};
Then
function loadXMLDoc()
{
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var string = xmlhttp.responseText;
obj = JSON.parse(string);
document.getElementById("myDiv").innerHTML = obj.Children;
}
}
xmlhttp.open("GET","r0.json",true);
xmlhttp.send();
return obj;
}
but after I call the function and pass the obj, like this:
var obj = loadXMLDoc();
initGL(canvas);
initShaders();
initBuffers(obj);
It cannot pass the value to function initBuffers. Why did that happen and how can I solve that? Thanks.
initBuffersinside the handler? what do you mean 'webgl cannot access them'? your code is executed in the same process, there is no other process, is there? is this inside a web browser?initBuffersfrom inside your anonymous function that you assign to theonreadystatechangeproperty.