at the moment, I’m writing a XML parser to parse a config file. I always try to keep the calls of “findproperty” low, because it’s very time-consuming. “findproperty” is called everytime you access a method or a property, like “objMyClass.myFunction()”. the AVM searches for the given property every time you use this syntax. if I need a property or method more than once, I always save it to a local variable.
I also tried this with XML.hasOwnProperty, what didn’t work for me. I got runtime errors, but no compilation errors. the used variable was always null.
this is the code I used:
[...] var funcHasOwnProperty:Function = xmlFileData.hasOwnProperty; [...]
as one would expect, this should be working without any problems. but you’re wrong, because funcHasOwnProperty will always be null. don’t ask me why and what adobe thought when designing this. maybe I should report a bug…
I still didn’t want to call the “findproperty” OP-Code for every XMLNode and every XMLAttribute, so I tried different things like coerce via
[...] var funcHasOwnProperty:Function = (xmlFileData.hasOwnProperty as Function); [...]
but that also didn’t work.
please note: if you call “xmlFileData.hasOwnProperty(‘foo’)” directly, everything is fine, but it seems that you can’t save it to a local variable.
finally, after different approaches, I found the solution by first coercing xmlFileData to Object
[...] var funcHasOwnProperty:Function = (xmlFileData as Object).hasOwnProperty; [...]
this is crazy, isn’t it?
this workaround may also work for other fields of application, but I didn’t test it yet.