Solved

Detecting type of control on stage

Posted on 2009-07-08
4
192 Views
Last Modified: 2013-11-11
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
Comment
Question by:moshem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24801680
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
 
LVL 2

Expert Comment

by:Iklu
ID: 24801694
I don't know if AS2 can.  Have you thought of using actionscript 3?
0
 
LVL 1

Author Comment

by:moshem
ID: 24801928
I dont think this can work in AS2

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

thanks
0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 24801978
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question