AS3 Error #1009
- Started
- Last post
- 3 Responses
- CyBrain
I'm running a simple flash movie to mentally prepare myself for a larger application of an array in a website. Here's an array of 10 buttons which position correctly.
http://talesfromthehead.com/rand…
and here is my document class:
http://pastebin.com/f61762b06After a for loop generates 10 squares, I randomly drop one of them down 5 pixels. (to prove I can reference each by array index). It all works fine except about 10% of the time, I get good old "error #1009 Cannot access a property or method of a null object reference. at ArrayNests()" (very informative)
I'm guessing that you have to wait for ThePressBtnsMC class to load and that I would need some kind of init eventListener. Anyone have and example of how that could be done?
- CyBrain0
Uh... nevermind, I was exactly right about this being wrong 10% of the time. When I used the line
pressBtn_array[Math.floor(Math.r... * pressBtnTotal)].y += 5;floor was creating an index result of 0 and my for loop went from 1 to 10. I initialized the array with null as the zeroeth entry — hence the "null object reference".
- Autokern0
Yep exactly.
When navigating/populating you array do this:
for (var i:uint = 0; i < pressBtnTotal; i++)
So you'll populate the thing starting from 0 which will give you less headaches- In general, keeping things zero-based will make life simpler.acrossthesea