# Pushing onto array

**URL:** <https://forum.kirupa.com/t/pushing-onto-array/259864>\
**Category:** Uncategorized\
**Created:** [May 9, 2008, 2:20pm UTC](https://forum.kirupa.com/t/pushing-onto-array/259864 "2008-05-09T14:20:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivaretro](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@vivaretro](https://forum.kirupa.com/u/vivaretro)\
**Post date:** [May 9, 2008, 2:20pm UTC](https://forum.kirupa.com/t/pushing-onto-array/259864/1 "2008-05-09T14:20:51Z")

</div>

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](http://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!

---

<div class="post-metadata">

**Author:** ![mpelland](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mpelland](https://forum.kirupa.com/u/mpelland)\
**Post date:** [May 9, 2008, 3:19pm UTC](https://forum.kirupa.com/t/pushing-onto-array/259864/2 "2008-05-09T15:19:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vivaretro](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@vivaretro](https://forum.kirupa.com/u/vivaretro)\
**Post date:** [May 9, 2008, 3:24pm UTC](https://forum.kirupa.com/t/pushing-onto-array/259864/3 "2008-05-09T15:24:13Z")

</div>

thanks much!
