4 Replies Latest reply on Apr 15, 2009 12:47 PM by m_hartnett

    Why the registered event cannot be heard (files content included)

    webvalue Level 1

      Hi,

       

      I posted a question earlier today about a problem using external customer event along with a chart created with actionscript. I think the files are better than words. If an expert can take a look at this and let me know how the event cannot be heard and how it can be heard, I will really appreciate it.

       

      3 files:

      ===============================================================

      1. ChartIt.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()" xmlns:local="*">
          <mx:Script>
              <![CDATA[
                  import mx.charts.PieChart;
                  import org.allus.examples.UpdateChartEvent;
                  import org.allus.examples.GenCharts;
                  import mx.collections.ArrayCollection;
                 
                  private var pieChart:PieChart = new PieChart();
                  private var genCharts:GenCharts = new GenCharts();
                 
                 
                  [Bindable]
                  private var chartData:ArrayCollection = new ArrayCollection( [
                  { Country: "USA", Gold: 35, Silver:39, Bronze: 29 },
                  { Country: "China", Gold: 32, Silver:17, Bronze: 14 },
                  { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]);
                 
                  private function init():void {
                      pieChart = genCharts.createPieChart(chartData, "Gold");
                      box.addChild(pieChart);
                      pieChart.addEventListener(UpdateChartEvent.UpdateChart, pieDoubleClicked);
                  }
                 
                  private function pieDoubleClicked(e:UpdateChartEvent):void {
                      trace("the pie chart was double clicked");
                  }
              ]]>
          </mx:Script>
         
          <mx:VBox width="50%" height="50%" id="box" borderStyle="solid"/>
      </mx:Application>

       

      ===============================================================

      2. GenChart.as:

       

      package org.allus.examples
      {
          import mx.charts.PieChart;
          import mx.charts.series.PieSeries;
          import mx.charts.events.ChartItemEvent;
          import mx.collections.ArrayCollection;
          import flash.events.EventDispatcher;
          import flash.events.Event;

       

          import org.allus.examples.UpdateChartEvent;
         
          public class GenCharts extends EventDispatcher
          {
              private var apieChart:PieChart;
              private var pieSeries:PieSeries;
             
              public function GenCharts() {
                  super();
              }
             
              public function createPieChart(chartData:ArrayCollection, by:String):PieChart {
                 
                  apieChart = new PieChart();
                  apieChart.percentWidth = 100;
                  apieChart.percentHeight = 100;
                  apieChart.showDataTips = true;
                  apieChart.dataProvider = chartData;
                 
                  apieChart.addEventListener(ChartItemEvent.ITEM_DOUBLE_CLICK, pieChartItemDoubleClickedHandler);
                  apieChart.doubleClickEnabled = true;
                 
                  var mySeries:Array = new Array();
                     
                  pieSeries = new PieSeries();                   
                  pieSeries.field = by;               
                  mySeries.push(pieSeries);
                  apieChart.series = mySeries;

       

                  return apieChart;
              }
             
              private function pieChartItemDoubleClickedHandler(evt:ChartItemEvent):void {
                  dispatchEvent(new UpdateChartEvent(UpdateChartEvent.UpdateChart));
              } 
          }
      }

       

       

      ==============================================

      3. UpdateChartEvent.as

       

      package org.allus.examples
      {
          import flash.events.Event;
         
          public class UpdateChartEvent extends Event
          {   
              public static const UpdateChart:String = "updateChart";
              public function UpdateChartEvent(eventName:String) {
                  trace("the event was triggered.");
                  super(eventName);
              }
          }
      }