Copy link to clipboard
Copied
Hi,
when checking if a class or movieclip (class) has a property I usually check it with "this[prop]!=null". Works great if the varaible has a definition. And it works great on 'Objects' / object arrays. I noticed I can check with hasOwnProperty when a variable may not be definied. But sometimes this doesn't work (maybe because it is a inherited variable). Would be the only safe way to use a try and catch command? Or, when do I know what to use?
Copy link to clipboard
Copied
if varaible not having definition.
you get undefined.
so ..
if(this[prop] == undefined){
trace("variable is not defined.")
}
may help this
Copy link to clipboard
Copied
Using this inside a class would lead to Error #1069 saying the property is not defined and the trace command is not executed. I could use a try and catch command which is a bit unhandy.
Copy link to clipboard
Copied
I think the only way to do it using "this" is with try-catch. As you've seen, results depend on what "this" is. A dynamic object (Object, Array, MovieClip, etc) will not throw an error when accessing undefined properties, but a sealed (non-dynamic, ex: subclass of MovieClip not explicitly marked dynamic) object will throw.
Copy link to clipboard
Copied
Ahhh, thank you. Exactly what I was looking for!
So is there any disadvantage in things like performance when using my class as dynamic class?
Copy link to clipboard
Copied
I've read there is a performance hit when using dynamic classes, though I have not tested the specifics. You also lose the advantage of type safety. In AS3 you should try to type all of your variables so you can avoid the introspection/reflection causing your problems. Type-related problems can then be caught at compile time.