0
votes

I have two questions regarding the Flex combo box.

  1. The string representing the function name will be read from xml @ run time.

    var combo:ComboBox = new ComboBox(); combo.labelFunction = "functionName";

How can I achieve this?

  1. So the first name, which is to be displayed in the combo box, can be only retrieved by accessing another DTO, called person and then its first name.

    var combo:ComboBox = new ComboBox(); combo.labelField= "person.firstName";

My class looks like this,

public class Test
{
     public var person:PersonDTO;
}

public class PersonDTO
{
     public var firstName:String;
}

Is it possible to access any multi-level text using the combo box label field ?

2

2 Answers

2
votes

You need to pass the function not the name. Doing this

combo.labelFunction = "functionName";

Is passing a string.

The only work around I can think of is to make a switch statement with one case for each function you may have. Then call that with "case" from within your xml.

switch( xml.@labelfunction ){
   case 'func1':
      combo.labelFunction = this.func1;
      break;
   case 'func2':
      combo.labelFunction = this.func2;
      break;
}

Its hacky but should work.

0
votes

ad 1) labelFunction

Calling functions when you know only the name as String is quite easy. The following snippets shows how you can execute a function that is a member of the same class. In case you need to call a function from another class replace this with the according variable name.

private function comboBox_labelFunction(item:Object):String
{
    var functionName:String = myXml.@labelFunctionName;
    return this[functionName](item);
}

ad 2) labelField

It's normally not possible to use "person.firstName" as labelField. However, you should be able use it within your labelFunction. Something like this should work...

private function comboBox_labelFunction(item:Object):String
{
    var labelField:String = "person.firstName";
    var attributeNames:Array = labelField.split(".");

    for each (var attributeName:String in attributeNames)
    {
        if (item && item.hasOwnProperty(attributeName))
            item = item[attributeName];
        else
            return null;
    }

    return item;
}