Skip to main content
Inspiring
May 10, 2006
Answered

Protoyping problem

when prototyping an existing class, for example:

Array.prototype.myMethod = function():Void{
//Perform some action here
}

for...each loops return the new method, for exmple, after the previous prototype has been declared:

my_arr = new Array[1,2,3]
for(i in my_arr){
trace(i)
}
should return '2,1,0' but instead returns 'myMethod,2,1,0'
this means that it will now be impossible to loop through an array in this way without first knowing, and then accounting for any protoypes that have been declared.
is there anything wrong with this prototype declaration that is causing this behavior? any help is much appreciated....
This topic is closed to new replies. Start a new post to keep the conversation going.
RothrockCorrect answer
Inspiring
May 10, 2006
No you aren't doing anything "wrong." That is how it works.

There is, however, a secret way to stop it. It is called ASSetPropFlag. See this tutorial:

http://www.flashguru.co.uk/assetpropflags/

So I think it would be:

ASSetPropFlag(Array.prototype,"myMethod",1)

I think?

2 replies

Inspiring
May 10, 2006
Rothrock, you are officially the man, or the woman, as the case may be. That did the trick perfectly. Thanks so much for bringing this to my attention
Translate
RothrockCorrect answer
Inspiring
May 10, 2006
No you aren't doing anything "wrong." That is how it works.

There is, however, a secret way to stop it. It is called ASSetPropFlag. See this tutorial:

http://www.flashguru.co.uk/assetpropflags/

So I think it would be:

ASSetPropFlag(Array.prototype,"myMethod",1)

I think?
Translate