Pushing onto array

I’m just learning how to do an array and am apparently not getting it completely.
I have data from an xml file that I’m loading into my .as file. I need to have each
piece of info pushed onto an array, but I keep getting error messages. Here’s the
code:

package
{
import flash.display.;
import flash.events.
;
import flash.net.*;

public class XMLLoader extends Sprite 
{
    private var electionData:XML;
    private var urlLoader:URLLoader;
    
    public function XMLLoader ()
    {
        
        var urlRequest:URLRequest = new URLRequest("http://www.kgwcreative.com/election/results.xml");
        urlLoader = new URLLoader();
        urlLoader.addEventListener(Event.COMPLETE, completeListener);
        urlLoader.load(urlRequest);
        
        resultsArray();
        
        
            
    }
    private function completeListener(e:Event):void
    {
        electionData = new XML(urlLoader.data);
        //trace("electionData.toXMLString is " + electionData.toXMLString());    
        
    }
    
    public function resultsArray():void
    {
        var xmlResults:Array = [];
        xmlResults.push(electionData[0]);
        trace (xmlResults);
        
        
        
        
        
    }
}

}

I keep getting this error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at XMLLoader/resultsArray()
at XMLLoader()
at Document()

any suggestions much appreciated!

chances are that electionData hasn’t been set by the time that you are calling the resultsArray method. I would recommend calling it from the completeListener. electionData is being assigned a value in the completeListener which only fires once the XML has been loaded, but you are calling resultsArray right away

thanks much!