Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Detecting type of control on stage

Hi,

I am trying to build an AS2 logic that first detects the type of control and then checks it according to it's type

if I test an input text control :

trace (tyepof (aa_txt));

I get "Input" which is great

if I do the same for a checkbox or combobox I get "movieclip" which is not unique and does not help me identify the type of control I am dealing with..

how can I tell which type is it in runtime ?

thanks
0
moshem
Asked:
moshem
  • 2
1 Solution
 
ChristoferDutzCommented:
I use the function flash.utils.getQualifiedClassName to get the fully qualified class name of an object. Maybe this helps you a little.

The code below uses getQualifiedClassName to find out if a class is an "Enum" (A class generated by the flex builder to represent a Java Enum in Flex ... I know It's not a real Enum)
// An Enum is defined by having a property that equals
// the class name with a prefix of "_". If such a property
// exists, this class is very propable an enum.
protected function isEnum(value:Object):Boolean
{
    var qualifiedClassName:String = getQualifiedClassName(value);
    var className:String = qualifiedClassName.substring(qualifiedClassName.lastIndexOf(":") + 1, qualifiedClassName.length);
    var propName:String = "_" + className;
    var hasProp:Boolean = value.hasOwnProperty(propName);
    return hasProp;
}

Open in new window

0
 
IkluCommented:
I don't know if AS2 can.  Have you thought of using actionscript 3?
0
 
moshemAuthor Commented:
I dont think this can work in AS2

I can't work with AS3 in this project..

thanks
0
 
ChristoferDutzCommented:
Oh gee  ... my mistake ... Flex2 didn't use ActionScript 2 ... sorry. Then my approach will not work.

Using the following code you should be able to get the class-object of your instance. Hope it works in ActionScript 2:
var myClass:Class = Object(myObj).constructor;

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now