title: create private var yada:Whatever; depending on xml count
body: <p>I am trying to declare private variables that will be used elsewhere in my flex mxml main application. But I need to only create the variables when their is an equal number in my xml file.</p>
  
  <p>My xml snippet looks like this:</p>
  
  <pre><code>&lt;POIs&gt;
      &lt;location&gt;
              &lt;name&gt;jane&lt;/name&gt;
              &lt;lat&gt;12345&lt;/lat&gt;
              &lt;long&gt;12345&lt;/long&gt;
              &lt;iconFile&gt;jane_icon.gif&lt;/iconFile&gt;
              &lt;imageFile&gt;jane_img.swf&lt;/imageFile&gt;
              &lt;motion&gt;no&lt;/motion&gt;
      &lt;/location&gt;
      &lt;location&gt;
              &lt;name&gt;john&lt;/name&gt;
              &lt;lat&gt;23456&lt;/lat&gt;
              &lt;long&gt;23456&lt;/long&gt;
              &lt;iconFile&gt;john_icon.gif&lt;/iconFile&gt;
              &lt;imageFile&gt;john_img.swf&lt;/imageFile&gt;
              &lt;motion&gt;no&lt;/motion&gt;
      &lt;/location&gt;
  &lt;/POIs&gt;
  </code></pre>
  
  <p>My main flex mxml file looks like this:</p>
  
  <pre><code>//------------------------------------------------------------------------------0
  private var locPointMarker0:PointMarker;
  private var locPointMarker0_lat:Number;
  private var locPointMarker0_long:Number;
  
  //------------------------------------------------------------------------------1
  private var locPointMarker1:PointMarker;
  private var locPointMarker1_lat:Number;
  private var locPointMarker1_long:Number;
  
  //------------------------------------------------------------------------------2
  private var locPointMarker2:PointMarker;
  private var locPointMarker2_lat:Number;
  private var locPointMarker2_long:Number;
  
  //------------------------------------------------------------------------------3
  private var locPointMarker3:PointMarker;
  private var locPointMarker3_lat:Number;
  private var locPointMarker3_long:Number;
  </code></pre>
  
  <p>I don't want to declare 2000 private variables when my xml might only have 500 locations. </p>
  
  <p>Here is how my xml is being added to my flex app:</p>
  
  <pre><code>public function getXMLData():void
  {   
      var locXMLLoader:URLLoader = new URLLoader(locXMLURL);
      locXMLLoader..addEventListener(Event.COMPLETE, xmlLoaded);  
      function xmlLoaded(e:Event):void
      {
          try
          {
              locXML = XML(locXMLLoader.data);
              locXML.location.(parseLocXML(
                  valueOf().name.toString(),
                  parseFloat(valueOf().lat.toString()),
                  parseFloat(valueOf().long.toString()),
                         valueOf().iconFile.toString(),
                         valueOf().imageFile.toString(),
                         valueOf().motion.toString()));
          } catch(e:Error)
          {
              trace("XML Load Error:  " + e.message)
              return;
          }
      }
  }
  
  public function parseLocXML(nodeName:String, lat:Number, 
              long:Number, iconFile:String, 
              imageFile:String, motion:String):void
  
  {   
      if (XMLpCounter==0)
      {
      addMarkers(); ///this is just one of the functions that requires the private vars
      }
      XMLpCounter++;
  }
  </code></pre>
  
  <p>I tried the similar code below, but it doesn't work because locXML isn't defined really till its is parsed.</p>
  
  <pre><code>//------------------------------------------------------------------------------1
  if(locXML.location.length()&gt;=1){
      trace("1 has been added as a variable");
      private var locPointMarker1:PointMarker;
      private var locPointMarker1_lat:Number;
      private var locPointMarker1_long:Number;}
              //------------------------------------------------------------------------------2
  if(locXML.location.length()&gt;=2){
      trace("2 has been added as a variable");
      private var locPointMarker2:PointMarker;
      private var locPointMarker2_lat:Number;
      private var locPointMarker2_long:Number;}
  </code></pre>
  
  <p>Is it possible to wait until the xml has loaded before declaring these variables?</p>