Bonjour,

Alors voilà, j'ai un problème concernant le tri d'un arrayCollection.
Cela me semblait pas trop compliqué à mettre en place après 2-3 recherches sur Internet.

Mais en fait, en reprenant cet exemple http://blog.flexexamples.com/2007/08...-sort-classes/ dans mon code, je ne parvient pas à obtenir un arrayCollection trié.

Le code est disposé comme suit :
Dans la fonction init() :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
var i:int;
 
/* Initialize and populate the ArrayCollection object. */
arrColl = new ArrayCollection();
for (i = 0; i < 20; i++) {
	arrColl.addItem({data:getRandomNumber().toFixed(4)});
}
La fonction getRandom() :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
private function getRandomNumber():Number 
{
  return Math.random() * 10000;
}
Et enfin la fonction qui va trier l'arrayCollection :
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
 
private function button_click():void 
{
  /* Create the SortField object for the "data" field in the ArrayCollection object, and make sure we do a numeric sort. */
	var dataSortField:SortField = new SortField();
	dataSortField.name = "data";
	dataSortField.numeric = true;
 
	/* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
	var numericDataSort:Sort = new Sort();
	numericDataSort.fields = [dataSortField];
 
	/* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
	arrColl.sort = numericDataSort;
	arrColl.refresh();
 
	Alert.show(ObjectUtil.toString(arrColl));
}
Et dans mon Alert.show, l'arrayCollection n'apparait pas trié.
Où est le problème ?

Merci !