1 Reply Latest reply on Aug 1, 2008 7:27 AM by Newsgroup_User

    problem in resetting arrayCollection

    smonika15 Level 1
      Hi ,

      In my application there is a grid and a button on the panel.there is a funtion toggle() in actionscript to handle the click event of the button.
      this funtion toggle the selected elements like after click selected element becoms unselected and unselected becomes selected.
      private function toggle(event:Event):void
      {
      var numChildren:Number = this.myGrid.rawChildren.numChildren;

      for(var i:Number = 2; i < numChildren; i++)
      {
      var el = this.myGrid.rawChildren.getChildAt(i);
      var clearTiles:Array = new Array();
      var tArr:Array = new Array();
      var newSelected:ArrayCollection = new ArrayCollection();
      var newUnSelected:ArrayCollection = new ArrayCollection();
      var rowChildren:Number = el.rawChildren.numChildren;
      // Start iterating at 1, so to avoid trying to select the label
      for(var j:Number = 1; j < rowChildren ; j++){
      var cell = el.rawChildren.getChildAt(j);
      if(cell.rawChildren.getChildAt(1).numChildren == 1){
      // an empty cell will return 0 above
      var tile = cell.rawChildren.getChildAt(1).getChildAt(0);
      clearTiles.push(tile);
      }
      }
      // now we'll loop through the tiles in the row.

      for(j = 0; j < clearTiles.length; j++)
      {

      if(clearTiles[j].isSelected == true){
      //Alert.show("inside 3 forlop");
      clearTiles[j].unselect();
      newUnSelected.addItemAt(clearTiles[j].name,clearTiles[j].id);
      }
      else
      {

      tArr.push(clearTiles[j]);
      //Alert.show("i m here:");
      //Alert.show("clearTiles[j].id::"+clearTiles[j].id);

      newSelected.addItemAt(clearTiles[j].name,clearTiles[j].id);
      clearTiles[j].doSelect();
      //Alert.show("i m after adding:");
      //Alert.show("tile id"+tile.id);
      }
      }
      }
      //Alert.show("length of the final selection1::"+newSelected.length);


      selectedTilesAC = newSelected;
      selectedTilesSecChart = newSelected;
      selectedTiles = tArr;
      //Alert.show("length of the final selection2::");
      //selectedTilesAC = newSelected as ArrayCollection;

      Alert.show("tArr tiles length in toggle :"+tArr.length);
      matrixSubChart.selectedTiles = selectedTilesSecChart;
      ExternalInterface.call("manageButtons", selectedTilesAC);

      }


      this function worksperfect first time but second time when the event fired everything is working fine only newSelected array collection has zero length while the data is coming all values are coming but it is not adding the data in the arrayCollection, infact tArr array also shows zero length.


      it is very strange behaviour because it is working perfectly first time an d next time value sare coming only thing is , those are not being added in the array and arrayCollection.


      Please please help me in this.


      Thanks and Regards
      smonika15






        • 1. Re: problem in resetting arrayCollection
          Level 7

          "smonika15" <webforumsuser@macromedia.com> wrote in message
          news:g6v4iv$q3i$1@forums.macromedia.com...
          > Hi ,
          >
          > In my application there is a grid and a button on the panel.there is a
          > funtion
          > toggle() in actionscript to handle the click event of the button.
          > this funtion toggle the selected elements like after click selected
          > element
          > becoms unselected and unselected becomes selected.
          > private function toggle(event:Event):void
          > {
          > var numChildren:Number = this.myGrid.rawChildren.numChildren;
          >
          > for(var i:Number = 2; i < numChildren; i++)
          > {
          > var el = this.myGrid.rawChildren.getChildAt(i);
          > var clearTiles:Array = new Array();
          > var tArr:Array = new Array();
          > var newSelected:ArrayCollection = new ArrayCollection();
          > var newUnSelected:ArrayCollection = new ArrayCollection();
          > var rowChildren:Number = el.rawChildren.numChildren;
          > // Start iterating at 1, so to avoid trying to select the label
          > for(var j:Number = 1; j < rowChildren ; j++){
          > var cell = el.rawChildren.getChildAt(j);
          > if(cell.rawChildren.getChildAt(1).numChildren == 1){
          > // an empty cell will return 0 above
          > var tile = cell.rawChildren.getChildAt(1).getChildAt(0);
          > clearTiles.push(tile);
          > }
          > }
          > // now we'll loop through the tiles in the row.
          >
          > for(j = 0; j < clearTiles.length; j++)
          > {
          >
          > if(clearTiles[j].isSelected == true){
          > //Alert.show("inside 3 forlop");
          > clearTiles[j].unselect();
          > newUnSelected.addItemAt(clearTiles[j].name,clearTiles[j].id);
          > }
          > else
          > {
          >
          > tArr.push(clearTiles[j]);
          > //Alert.show("i m here:");
          > //Alert.show("clearTiles[j].id::"+clearTiles[j].id);
          >
          > newSelected.addItemAt(clearTiles[j].name,clearTiles[j].id);
          > clearTiles[j].doSelect();
          > //Alert.show("i m after adding:");
          > //Alert.show("tile id"+tile.id);
          > }
          > }
          > }
          > //Alert.show("length of the final selection1::"+newSelected.length);
          >
          >
          > selectedTilesAC = newSelected;
          > selectedTilesSecChart = newSelected;
          > selectedTiles = tArr;
          > //Alert.show("length of the final selection2::");
          > //selectedTilesAC = newSelected as ArrayCollection;
          >
          > Alert.show("tArr tiles length in toggle :"+tArr.length);
          > matrixSubChart.selectedTiles = selectedTilesSecChart;
          > ExternalInterface.call("manageButtons", selectedTilesAC);
          >
          > }
          >
          >
          > this function worksperfect first time but second time when the event fired
          > everything is working fine only newSelected array collection has zero
          > length
          > while the data is coming all values are coming but it is not adding the
          > data in
          > the arrayCollection, infact tArr array also shows zero length.
          >
          >
          > it is very strange behaviour because it is working perfectly first time an
          > d
          > next time value sare coming only thing is , those are not being added in
          > the
          > array and arrayCollection.
          >
          >
          > Please please help me in this.

          Use the dataProvider's interface to change the data. Don't interfere with
          the way the grid handles its children.

          HTH;

          Amy