Get the type in flex

18,662

Solution 1

You can either test against a particular class using the "is" operator or you can use flash.utils.getQualifiedClassName() (you pass it your object) - which will return a string of the fully qualified class name.

Solution 2

ITS WORKING :)

Following is the way I solved this issue

switch( true )
   {
    case item is Customer_SF:
     c = item as Customer_SF;
     break;

    case item is Opportunity:
     o = item as Opportunity; 
     break;

    case item is Product:
     o = ( item as Product )._opportunity;
     break;
    default:
     return true;
   }

Solution 3

Try to use the "className" property.

It should return "TextInput" or "Button" depending the case

for each (var item:* in myArray)
{
    if(item.hasProperty('className'))
    {
        trace("item ["+i+"] is :" + item['className']);
    }
}

Solution 4

The operator "is" represents one option.

Then there is the operator instanceof, which might or might not be useful depending on situation.

Also there's the ObjectUtil class with static method getClassInfo. This one returns more than just the object's class name.

Operator "typeof" unfortunately is useless for classes.

And, as Branden Hall already suggested, flash.utils.getQualifiedClassName().

Solution 5

here's some simple pseudo-code which demonstrates how to use the is operator for what you want to do:

for each (var item:* in myArray)
{
    if (item is TextInput)
        doSomethingWithTextInput(item as TextInput);
    else if (item is RadioButton)
        doSomethingWithRadioButton(item as RadioButton);
}
Share:
18,662
Sebastian Müller
Author by

Sebastian Müller

Financial Engineer, Software Engineer, Product Management, Mathematics, Finance, Insurance, IT Architect

Updated on June 23, 2022

Comments

  • Sebastian Müller
    Sebastian Müller about 2 years

    can someone tell me how I can identify the type of an object in flex? In particular I have an array where I store multiple types in (but all UIComponents) now as I evaluate the array I want to find out whether I have a TextInput Control or a RadioButton. Does someone have an idea?

    Thanks in advance