10 Replies Latest reply on Nov 8, 2010 11:36 AM by JoGlez

    Can't clear array AS3

    JoGlez

      Hi I am using the code provided below which i got from an Adobe Flex 4 page. And I would like to add a "clear" functionality, I thought that the way to go was to just clear the data provider but it's not working.. any help would be great!!!

      What i've done: made a button that clears data provider --> ConfigData.Global.newDataProviderAC.removeAll(); <-- chart remains in tact..

       

      code:

       

      public function explodePiece(e:Event):void {
                  explodedPiece = new Array();          
                  explodedPiece[newSeries.selectedIndex] = .2;
                  newSeries.perWedgeExplodeRadius = explodedPiece;
              }
             
              public function setupPieChart():PieChart {    
                 
                  newChart  = new PieChart();
                  newChart.showDataTips = true;           
                  newChart.selectionMode = "single";
                  newChart.dropEnabled= true;
                  newChart.dragEnabled= false;
                  newChart.horizontalCenter=0;
                 
                  newChart.height = 350;
                  newChart.width = 350;
                 
                  newChart.addEventListener("dragEnter", doDragEnter);
                  newChart.addEventListener("dragDrop", doDragDrop);
                 
                  newChart.dataProvider = ConfigData.Global.newDataProviderAC;
                 
                  newSeries = new PieSeries();
                  newSeries.field = ConfigData.Global.CompareField;
                  newSeries.nameField = ConfigData.Global.CompareNameField;
                 
                  var newSeriesArray:Array = new Array();
                  newSeriesArray.push(newSeries);
                  newChart.series = newSeriesArray;
                 
                  newChart.addEventListener(ChartItemEvent.CHANGE, explodePiece);
                 
                  // Create a legend for the new chart.
                  return newChart;
              }
             
              public function doDragEnter(event:DragEvent):void {
                  var dragTarget:ChartBase = ChartBase(event.currentTarget);
                  DragManager.acceptDragDrop(dragTarget);
              }
             
              public function doDragDrop(event:DragEvent):void {
                  var dropTarget:ChartBase=ChartBase(event.currentTarget);
                 
                  var items:Array = event.dragSource.dataForFormat("chartitems") as Array;
                 
                  for(var i:uint=0; i < items.length; i++) {
                      if (dropTarget.dataProvider.contains(items[i].item)) {
                      } else {
                          dropTarget.dataProvider.addItem(items[i].item);               
                      }               
                  }
              }