title: JavaScript global variable to store kml model object
body: <p>I'm developing a webpage to display google earth and a kml object. There will be two frames, one is the earth + kml object, the other is to display kml object's info like altitude, latitude, longitude...</p>
  
  <p>I'm done with load the kml object and display its info on the page. Now, I want to add some events to control the kml object with keyboard, to move it and reflect all the changes in coordination onto the display frame.</p>
  
  <p>In order to do that, I create my own object:</p>
  
  <pre><code>    //Constructor for object ModelInfo
  function ModelInfo(name) {
      var me = this;
      me.model = null;
      me.name = name;
      me.lon = 120.89250214028388;
      me.lat = 22.17480037801846;
      me.alt = 15.00;
      me.heading = 0.0;
      me.tilt = 0.0;
      me.roll = 0.0;
      me.kmlUrl = "";
      me.ALTITUDE_MODE = ge.ALTITUDE_RELATIVE_TO_GROUND;
      me.scaleX = 0.3;
      me.scaleY = 0.3;
      me.scaleZ = 0.3;
  }
  </code></pre>
  
  <p>When I fetchKml, I store the kml model into my objectInfo.model:</p>
  
  <pre><code>    // Fetch a  KML file and show it
  function finished(object, objInfo) {
      if (!object) {
          // wrap alerts in API callbacks and event handlers
          // in a setTimeout to prevent deadlock in some browsers
          setTimeout(function() {
              alert('Bad or null KML.');
          }, 0);
          return;
      }
  
      var modelPlacemark;
      walkKmlDom(object, function() {
          if (this.getType() == 'KmlPlacemark' &amp;&amp; this.getGeometry()
                  &amp;&amp; this.getGeometry().getType() == 'KmlModel') {
              modelPlacemark = this;
          }
      });
  
      var model = modelPlacemark.getGeometry();
  
      objInfo.model = model;
  </code></pre>
  
  <p>This is how I call fetchKml</p>
  
  <pre><code>    shutter = new ModelInfo("Shutter"); //shutter is global variable
  
      shutter.kmlUrl = 'http://120.125.80.113/kml/student/space_shuttle_23_20110812a/space_shuttle_23_20110812a_SP.kmz';
      google.earth.fetchKml(ge, shutter.kmlUrl, function(obj) {
          finished(obj, shutter);
      });
  </code></pre>
  
  <p>But the problem is, after fetchKml finishes, I try to access <strong>shutter.model</strong>, <strong>it is always null</strong>, but when I access shutter.model <strong>from within function finished</strong>, <strong>it is not null</strong></p>
  
  <p>So my question is how did it happen? Is there anyway to store kml object in a global variable to modify its attribute later?</p>
  
  <p>Thanks,
  Hans</p>