title: javascript - cannot retrieve array data
body: <p>I am trying to write a OBJMesh model reader and I've got the OBJMesh class setted up, but when I try to retrieve the stored data in the array by creating the OBJMesh object and call the get function, it doesn't do it.</p>
  
  <p>Here's the code</p>
  
  <p><strong>OBJMesh.js</strong></p>
  
  <pre><code>function OBJMesh(file)
  {
      this.modelVertex = [];
      this.modelColor = [];
      this.init = false;
  
      var rawFile = new XMLHttpRequest();
      rawFile.open("GET", file, true);
  
      var objmesh = this;
      rawFile.onreadystatechange = function ()
      {
  
          if(rawFile.readyState == 4)
          {
              if(rawFile.status === 200 || rawFile.status === 0)
              {
                  var allText = rawFile.responseText;
                  var lines = allText.split("\n");
  
  
                  for(var i = 0; i &lt; lines.length; i ++)
                  {
                      var lineData = lines[i];
                      var lineString = lineData.split(" ");
  
                      if(lineString[0] === "v")
                      {
  
                          var x = parseFloat(lineString[1]);
                          var y = parseFloat(lineString[2]);
                          var z = parseFloat(lineString[3]);
  
                          objmesh.modelVertex.push(x);
                          objmesh.modelVertex.push(y);
                          objmesh.modelVertex.push(z);
  
                          objmesh.modelColor.push(0.0);
                          objmesh.modelColor.push(0.0);
                          objmesh.modelColor.push(0.0);
                          objmesh.modelColor.push(1.0);
  
                          //document.getElementById("textSection").innerHTML = objmesh.modelVertex[0];
                      }
                  }
              }
          }
          objmesh.init = true;
      }
  
      rawFile.send();
  }
  
  OBJMesh.prototype.getModelVertex = function ()
  {
      return this.modelVertex;
  };
  
  OBJMesh.prototype.getModelColor = function ()
  {
      return this.modelColor;
  };
  
  OBJMesh.prototype.getInit = function ()
  {
      return this.init;
  };
  </code></pre>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>var cubeModel;
  
  function main()
  {
      cubeModel = new OBJMesh("file:///Users/DannyChen/Desktop/3DHTMLGame/cube.obj");
  
      while(cubeModel.getInit() === false)
      {
          //wait for it
      }
  
      var cubeVertex = cubeModel.getModelVertex();
  
      document.getElementById("textSection").innerHTML = cubeVertex[0];
  
  }
  </code></pre>
  
  <p>it just keeps printing out "undefined". Why's that? and how can I fix it??</p>