Bonjour à tous.

Je suis débutant et j'ai un problème de traitement d'un combobox rempli grâce à un fichier XML.

Structure du fichier XML :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<liste>
<titre>Personnes présentes</titre>
<test>
<valeur>1</valeur>
<nom>Personne 1</nom>
<description>Description personne 1</description>
</test>
</liste>
Puis le programme :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0" encoding="utf-8"?>
 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="400" creationComplete="feedRequest.send()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
 
[Bindable]
public var selectedItem:Object;
]]>
</mx:Script>
 
<mx:HTTPService id="feedRequest" url="test.xml" useProxy="false"/>
 
<mx: Panel title="{feedRequest.lastResult.liste.titre}" x="10" y="10" width="430" height="380" layout="absolute" titleIcon="@Embed('area.png')">
 
<mx:Label id="choixLabel" x="10" y="36" text="Selection :"/>
<mx:ComboBox id="tComboBox" width="210" x="190" y="34"
dataProvider="{feedRequest.lastResult.liste.test}"
labelField="nom"
data="valeur"
prompt="Choisissez..."
rowCount="3"
close="selectedItem=ComboBox(event.target).selectedItem"
/>
<mx:Label id="descLabel" x="10" y="62" width="390" textAlign="center" fontWeight="bold"
text="{tComboBox.selectedItem.description}"
/>
<mx:Text x="190" y="146" text="Label:{selectedItem.label}" width="210"/>
<mx:Text x="190" y="176" text="Data:{selectedItem.data}" width="210"/>
</mx: Panel>
</mx:Application>
Dans l'état actuel des choses :
- le titre de mon panel change correctement
- ma combobox est bien remplie
- la description s'affiche sans problème

Là où ça casse, c'est sur selectedItem.label et selectedItem.data. L'affichage renvoyé est toujours 'Label:null' et 'Data:null'.

Forcement, n'arrivant pas à récupérer l'état de la sélection du combobox, le traitement du résultat est impossible.

Quelqu'un pourrait-il m'aider ? D'avance je vous en remercie.

Edition du 23/01/08

Sur un autre forum, la solution m'a été fournie.

Pour ceux qui en aurait besoin, voici le fichier XML modifié (test.xml) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<liste>
	<titre>Nos membres</titre>
	<membre>
		<data>1</data>
		<nom>Membre n° 1</nom>
		<description>Description membre</description>
	</membre>
	<membre>
		<data>2</data>
		<nom>Membre n° 2</nom>
		<description>Description membre</description>
	</membre>
</liste>
Puis le code Flex :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="400" creationComplete="feedRequest.send()"> 
<mx:Script> 
<![CDATA[ 
import mx.controls.Alert; 
 
[Bindable] 
public var selectedItem:Object; 
]]> 
</mx:Script> 
 
<mx:HTTPService id="feedRequest" url="test.xml" useProxy="false"/> 
 
<mx:Panel title="{feedRequest.lastResult.liste.titre}" x="10" y="10" width="430" height="380" layout="absolute" titleIcon="@Embed('area.png')"> 
 
  <mx:Label id="choixLabel" x="10" y="36" text="Selection :"/> 
  <mx:ComboBox id="tComboBox" width="210" x="190" y="34" 
    dataProvider="{feedRequest.lastResult.liste.test}" 
    labelField="nom" 
    prompt="Choisissez..." 
    rowCount="3" 
    close="selectedItem=ComboBox(event.target).selectedItem" /> 
  <mx:Label id="descLabel" x="10" y="62" width="390" textAlign="center"
    fontWeight="bold" 
    text="{tComboBox.selectedItem.description}" /> 
  <mx:Text x="190" y="146" text="Label:{selectedItem.label}" width="210"/> 
  <mx:Text x="190" y="176" text="Data:{selectedItem.data}" width="210"/> 
</mx:Panel> 
</mx:Application>
Une toute petite chose à changer dans le fichier XML : <valeur></valeur> devenant <data></data> et dans le code Flex, la ligne data="valeur" dans la combobox ne sert à rien donc supprimer.