• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

checking for property of a class

Contributor ,
May 03, 2013 May 03, 2013

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?

TOPICS
ActionScript

Views

807

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2013 May 03, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 06, 2013 May 06, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 07, 2013 May 07, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 07, 2013 May 07, 2013

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 07, 2013 May 07, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines