1 Reply Latest reply on Jun 30, 2008 4:46 AM by CalRaiden©

    modifying Array position with IViewCursor

    CalRaiden©
      I have array print with command Alert.show(''+ObjectUtil.toString(arrColl));
      (mx.collections::ArrayCollection)#0
      filterFunction = (null)
      length = 4
      list = (mx.collections::ArrayList)#1
      length = 4
      source = (Array)#2
      [0] (Object)#3
      2008-03 = "1473"
      2008-03p = "40,19"
      desc = "Usuários únicos"
      [1] (Object)#4
      2008-03 = "1476"
      2008-03p = "-16,80"
      desc = "Novos usuários"
      [2] (Object)#5
      2008-03 = "53114"
      2008-03p = "39,25"
      desc = "Sessões"
      [3] (Object)#6
      2008-03 = "45"
      2008-03p = "-97,78"
      desc = "Tarifação"
      uid = "8B1A7D6D-62D1-C9BF-85DD-C538F40ED10D"
      sort = (null)
      source = (Array)#2


      I would like to modify the position of the Array, moving the last key for the beginning.
      thus:
      [0] (Object)#3
      desc = "Usuários únicos"
      2008-03 = "1473"
      2008-03p = "40,19"
      [1] (Object)#4
      desc = "Novos usuários"
      2008-03 = "1476"
      2008-03p = "-16,80"
      [2] (Object)#5
      desc = "Sessões"
      2008-03 = "53114"
      2008-03p = "39,25"
      [3] (Object)#6
      desc = "Tarifação"
      2008-03 = "45"
      2008-03p = "-97,78"

      my code source, but is not functioning. some tip of the error?
      /code]
      //Recebi o resultado e guarda em um array devido ordenação
      var arrColl:ArrayCollection = new ArrayCollection(event.data as Array);
      Alert.show(''+ObjectUtil.toString(arrColl));
      if (! runBefore) {
      runBefore=true;
      for (var i:int=0; i < arrColl.length; i++)
      {
      // Get an IViewCursor object for accessing the collection data.
      var myCursor:IViewCursor=arrColl .createCursor();
      // Get the original collection length.
      var oldLength:int=arrColl
      .length;
      myCursor.seek(CursorBookmark.LAST);
      // The cursor is initially at the first item; delete it.
      var removedItem:Object=Object(myCursor.remove());
      // The cursor is at the (new) first item;
      // move it to the firs item.
      myCursor.seek(CursorBookmark.FIRST, 0);
      // Add removedItem as the first item.
      myCursor.insert(removedItem);
      }

      var sort:Sort = new Sort();
      arrColl.sort=sort;
      // Refresh the collection view to apply the sort.
      arrColl.refresh();
      }

      //Guarda na variavel o array
      dgReport.dataProvider = arrColl;
      [/code]