1 Reply Latest reply on Dec 15, 2007 11:36 PM by jfizer

    Splice of a multidimensional array?

    jfizer Level 1
      Trying to splice a multidimensional array and getting odd results. I have two mx:list objects, both with arrays on the back end. One has a multidimensional array as its data provider containing three values. I can push the values from it into the other lists data provider by running a forEach loop thusly.

      private function onEach(item:*, index:int, array:Array):void {
      // Build a multi value array. field,value,display
      arr2.push( {data:Combo.selectedLabel, value:item[Combo.selectedLabel], display:String(Combo.selectedLabel + ":" + item[Combo.selectedLabel])} );
      }

      However, when I try to splice an item to move it to a new location in the list I get an unknown object structure back rather then the three value array I would expect.

      private function moveUp():void {
      //alert = Alert.show(String(selectList.selectedIndex));
      //alert = Alert.show(selColumns.toString());
      var selIndex:int = selectList.selectedIndex;
      var slice:Array;
      if(selIndex > 0) {
      slice = selColumns.splice(selIndex,1);
      selColumns.splice(selIndex-1,0,slice)
      selectList.selectedIndex=selIndex-1;
      }
      selectList.dataProvider.refresh();
      }

      Anyone see where I'm going wrong? The lack of an object inspector is making this rough since I have no idea what the structure is of the object I'm getting back by the selColumns.splice(selIndex,1); call.
        • 1. Re: Splice of a multidimensional array?
          jfizer Level 1
          Treating the splice variable as an array and just pulling the data from the array into it seems to work.

          private function moveUp():void {
          //alert = Alert.show(String(selectList.selectedIndex));
          var selIndex:int = selectList.selectedIndex;
          var slice:Object;
          if(selIndex > 0) {
          //slice = selColumns.splice(selIndex,1);
          slice = selColumns[selIndex];
          selColumns.splice(selIndex,1);
          selColumns.splice(selIndex-1,0,slice);
          selectList.selectedIndex=selIndex-1;
          }
          selectList.dataProvider.refresh();
          }