Associate Array issues with Flash AS3

I was writing some code to do word counts of a text file, which I needed to be able to access quickly, so using each word as the index into an associative array seemed like a good idea, but proved to have some hidden gotya’s.

Initialy I used the Array class as the Associative array, but when reading one specific file I got this error

ReferenceError: Error #1037: Cannot assign to a method every on Array.

This was caused because “every” is a method in the Array Class.

The fix for this is to prepend a character e.g. “_” in front of the “word” so that there would not be clashes with any published methods or properties of the Array class as none of them start with “_”

Subsequentally reading the Live Docs on Arrays, I noticed that Adobe recommends that Arrays are not used for associative arrays, and that the Object class should be used instead. So I change my code to use Object instead of Array.

But, note of caution, the Object class does have several built in methods and properties, For Example “hasOwnProperty” hence if the text file I was indexing, contained code this would still be a problem
I did a quick test and got the error
ReferenceError: Error #1037: Cannot assign to a method hasOwnProperty on Object

So prepending a “_” is still necessary for the Object class to guarantee no nasty runtime errors !