title: How do I order datagrid columns in AS3?
body: <p>I'm using the following code to load XML directly into a datagrid:</p>
  
  <pre><code>import flash.events.Event;
  import fl.data.DataProvider;
  import flash.net.URLRequest;
  
  var loader:URLLoader = new URLLoader();
  
  loader.addEventListener(Event.COMPLETE, directoryXMLLoaded);
  
  function directoryXMLLoaded(e:Event){
      var dp:DataProvider = new DataProvider(new XML(e.target.data));
      directoryGrid.dataProvider = dp;
  }
  
  loader.load(new URLRequest("xml/directory.xml"));
  </code></pre>
  
  <p>How can I reorder my columns based on the title?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My XML looks like this: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;contacts&gt;
  &lt;contact first="Moshe" last="Doe" address="555 5th St" city="Somwhere" state="AA" zip="555555" phone="555-555-5555" /&gt;
  &lt;contact first="Moshe" last="Doe" address="555 5th St" city="Somwhere" state="AA" zip="555555" phone="555-555-5555" /&gt;
  &lt;contact first="Moshe" last="Doe" address="555 5th St" city="Somwhere" state="AA" zip="555555" phone="555-555-5555" /&gt;
  &lt;/contacts&gt;
  </code></pre>
  
  <p>I want the columns to appear in the order of the attributes (As first, last,address, city, state, zip, phone), but they are not. </p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>TheDarklnl has the correct answer. I implemented it  slightly differently though:</p>
  
  <pre><code>function directoryXMLLoaded(e:Event){
      var dp:DataProvider = new DataProvider(new XML(e.target.data));
      directoryGrid.addColumn("first");
      directoryGrid.addColumn("last");
      directoryGrid.addColumn("address");
      directoryGrid.addColumn("city");
      directoryGrid.addColumn("state");
      directoryGrid.addColumn("zip");
      directoryGrid.addColumn("phone");
      directoryGrid.dataProvider = dp;
  }
  </code></pre>