Skip to main content
Known Participant
May 9, 2008
Question

pushing on to an array

  • May 9, 2008
  • 5 replies
  • 685 views
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 the following error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at XMLLoader/resultsArray()
at XMLLoader()
at Document()
This topic has been closed for replies.

5 replies

kglad
Community Expert
Community Expert
May 9, 2008
you're welcome.
kglad
Community Expert
Community Expert
May 9, 2008
you make xmlResults non-local by NOT prefixing it with var inside a function body. so, declare the data type where you declared electionData, for example.

to learn how to parse xml, check the flash help files. or even easier, use electionData directly and flash autocompletion will suggest properties you can use.
vivaretroAuthor
Known Participant
May 9, 2008
Sounds good. Thanks very much!
kglad
Community Expert
Community Expert
May 9, 2008
ntbdy, he's created an array.
vivaretroAuthor
Known Participant
May 9, 2008
Okay, so I moved the array up to the previous function which doesn't get called until the listener is complete.
How do I make the xmlResults not local? Do I make it a Static variable? Sorry for the dumb questions but the last time I coded it was on a C-64.
The attached code now runs without errors but I think it loads everything into one variable.
This is an example of what's in the xml file its reading. Not sure how to get it to read each item individually:
<state>
<county>
<name>Baker</name>
<candidate>
<name>Clinton</name>
<percentage>43</percentage>
<votes>1095</votes>

</candidate>
<candidate>
kglad
Community Expert
Community Expert
May 9, 2008
electionData is undefined when your calling resultsArray(). (ie, don't call it until your complete listener executes.) in addition, you've made xmlResults local to resultsArray, so you won't be able to add more than one element to it and there's no reason to use a one element array.
Inspiring
May 9, 2008
> var xmlResults:Array = [];

Hi. You haven't actually created an array there. So when you try to push something onto a non-existent object, you get the "null object" error.

what you want:
var xmlResults:Array = new Array();
Inspiring
May 9, 2008
scratch this. Too much of going back and forth between syntax in as3, php, mysql and java is apparently making me dizzy

quote:

Originally posted by: ntbdy
> var xmlResults:Array = [];

Hi. You haven't actually created an array there. So when you try to push something onto a non-existent object, you get the "null object" error.

what you want:
var xmlResults:Array = new Array();