The swf10 compiler should already warn you if you reference an undeclared attribute. It's one of the benefits of compiling to swf10, it is a much stricter compiler.
I would not recommend using the 'in' operator for this purpose. On Oct 29, 2010, at 23:52, Antun Karlovac <[email protected]> wrote: > Hey Tucker, > > Thanks for your reply and detailed explanation. In my case, I'm coming to > Flash 10. I guess that the in operator might work. I'm specifically trying to > warn the developer if they have forgotten to declare an attribute. > > -Antun > > "P T Withington" <[email protected]> wrote: > >> Not in a forward-compatible cross-platform way. >> >> In Javascript, for a general Object, you can say: >> >> obj = { a: 3 }; >> >> if ('b' in obj) ... obj.b >> >> But OL classes are implemented as actual classes in some target >> runtimes, and in those runtimes, class instances are not plain objects, >> and the `in` operator is not (always) applicable. >> >> Luckily for you, Javascript does have the special "undefined" value >> [which we write as `(void)0`, because some Javascripts do _not_ ensure >> that `undefined` is undefined], which is different from all other >> values, including `null`. Usually this is sufficient to tell whether >> an attribute has been initialized or not. >> >> I'm hedging my bets above because currently, when we compile to swf10 >> (the strictest runtime so far), we do so in a way that the `in` >> operator _will_ work for most, but not all, OL instances; but I >> wouldn't want you to rely on that, because one of the performance >> features we are considering turning on will make that no longer true. >> >> In general, you don't want to be dynamically adding attributes to OL >> instances, so you shouldn't need to test for their existence. For us >> to continue to support that model going forward, we will pay a >> performance penalty. >> >> Maybe if you say what you are really trying to do, we can offer a >> better solution? >> >> On 2010-10-29, at 20:22, Antun Karlovac wrote: >> >>> Hi all, >>> >>> Does the OL runtime have a way to check if an attribute is declared >> (but not necessarily defined). >>> >>> e.g. I want to tell the difference between the following: >>> >>> <myclass> >>> <attribute name="myAttribute" /> >>> </myclass> >>> >>> <myclass> >>> </myclass> >>> >>> It's no use testing for undefined, because in the first case, >> myAttribute _is_ undefined. >>> >>> Thanks, >>> >>> Antun > > -- > Sent from my Android phone with K-9 Mail. Please excuse my brevity.
