1
votes

I have an XML that i retrieve from a call so all values are dynamic exept for the labels of the nodes(so I know that there is a appname that I have to display). I display appname in a ComboBox, then I need to get another value from another label in the same node, my xml has structure like so

<root>
  <item>
    <name>Hello</name>
    <version>World</version>
  </item>
  <item>
    <name>See_you</name>
    <version>soon</version>
  </item>
</root>

Now, I have a flex mx:ComboBox that has dynamic values, the user selects the label , for example Hello, and I need to find the corresponding node value, and the child value, so i can return World.

I can define the labels of the ComboBox via dataProvider, so it's done. Now I cannot get the selected value via trace(event.currentTarget.selectedItem.@label); (I have on change handler on the ComboBox) = that's 1 problem;

Second problem is how can I get a node value from an xml object if I have another node value in the same parent node( in this case)?

I'm stuck on this and running out of time, please help. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ i have it like this in my mxml

<mx:AddChild relativeTo="{VGroup}">
<mx:ComboBox id="AppListBox" change="AppListBox_changeHandler(Event.CHANGE)"/>
</mx:AddChild>

then i provide data, when I have it in my script, like so

AppListBox.dataProvider = appxml.item.appname.text();

appxml - is a that xml

Then I try to get the value of selected item, i tried like that:

protected function AppListBox_changeHandler(event:Event):void
{
trace(event.currentTarget.selectedItem.label);
trace(event.currentTarget.selectedItem.data);
trace(event.currentTarget.selectedItem.@label);
trace(AppListBox.selectedItem.label);
trace(AppListBox.selectedItem.@label);
trace(AppListBox.selectedItem.name);

it does not display anything. not even error

1
For the ComboBox dataprovider you can supply the list of item objects which means each selectedItem will have a .@name and a .@version then you can set labelField on the ComboBox to @name, in your change handler the comboBox.selectedItem.@version will have the corresponding value. If you don't follow please post your ComboBox code and the part that shows how the DP is provided to the combo box.shaunhusain
i have it like this in my mxml '<mx:AddChild relativeTo="{VGroup}"> <mx:ComboBox id="AppListBox"/> </mx:AddChild>' then i provide data, when I have it, like so 'AppListBox.dataProvider = appxml.item.appname.text();' appxml - is a that xmlCheslau Adamchyk
try trace("Some literal in your change handler"); to be sure it's hitting the handler and that the console is outputting values and it's just the case that all of those are somehow blank... which I find hard to believe, some of those should cause errors. Be sure you are running flash debug player helpx.adobe.com/flash-player/kb/find-version-flash-player.htmlshaunhusain
Furthermore I don't understand where appName is supposed to come from, I don't see it defined in the XML did you change name to appname? Please make your code that's posted consistent with what you currently have I believe it's in a half updated state, or else I'm missing something entirely.shaunhusain

1 Answers

1
votes

This all works fine for me.

[Bindable]
public var myXML:XML

private function init( ):void{
  this.myXML = new XML(     
  <root>
    <item>
      <name>Hello</name>
      <version>World</version>
    </item>
    <item>
      <name>See_you</name>
      <version>soon</version>
    </item>
  </root>
  );
}

private function appListBox_changeHandler(event:Event):void{
  trace( 'index   --' + appListBox.selectedIndex )
  trace( 'label   --' + appListBox.selectedLabel )
  trace( 'version --' + XML(appListBox.selectedItem).version )
  trace( 'item    --' + appListBox.selectedItem )
}


<comboBox:ExtendedComboBox 
  id="appListBox"
  dataProvider="{this.myXML.item}"
  labelField="name"
  itemRenderer="mx.controls.Label"
  change="appListBox_changeHandler(event)"
/>