0 Replies Latest reply on Sep 18, 2009 1:08 PM by Joe S.

    OLAP ... Adobe example used; need help fixing a bug (clearing variables on error)

    Joe S. Level 1

      Okay ...

      So I used one of the Adobe examples except now it's part of a container and it's using a datasource instead of the flatfile the example uses.  Also, for some reason I need to create a button instead of using the creationComplete to get it to work.  My problem is if the button is clicked to fast while it's loading the data (since another part of the application has a dropdown menu so you can requery information) you get an error and for some reason, you'll still get the same error even if the data is fully loaded and even if you change the parameter to reload the data.  My feeling is that the variables are not getting cleared out after it throws the error.


      So my question is what is the best way to clear out the variables (and how) when it throws an error.  The code for the page is below.





      <?xml version="1.0" encoding="utf-8"?>
      <v:MaxRestorePanel xmlns:mx="http://www.adobe.com/2006/mxml"
              import mx.collections.ICollectionView;
              import mx.rpc.AsyncResponder;
              import mx.rpc.AsyncToken;
              import mx.olap.OLAPQuery;
              import mx.olap.OLAPSet;
              import mx.olap.IOLAPQuery;
              import mx.olap.IOLAPQueryAxis;
              import mx.olap.IOLAPCube;
              import mx.olap.OLAPResult;
              import mx.events.CubeEvent;
              import mx.controls.Alert;
              import mx.collections.ArrayCollection;
              public var dp:ICollectionView = null;
              // Format of Objects in the ArrayCollection:
              //  data:Object = {
              //    customer:"AAA",
              //    product:"ColdFusion",
              //    quarter:"Q1"
              //    revenue: "100.00"
              //  }


              private function creationCompleteHandler3():void {
                  // You must initialize the cube before you
                  // can execute a query on it.


              // Create the OLAP query.
              private function getQuery(cube:IOLAPCube):IOLAPQuery {
                  // Create an instance of OLAPQuery to represent the query.
                  var query:OLAPQuery = new OLAPQuery;
                  // Get the row axis from the query instance.
                  var rowQueryAxis:IOLAPQueryAxis =
                  // Create an OLAPSet instance to configure the axis.
                  var productSet:OLAPSet = new OLAPSet;
                  // Add the Product to the row to aggregate data
                  // by the Product dimension.
                  // Add the OLAPSet instance to the axis.
                  // Get the column axis from the query instance, and configure it
                  // to aggregate the columns by the Quarter dimension.
                  var colQueryAxis:IOLAPQueryAxis =
                  var quarterSet:OLAPSet= new OLAPSet;
                  return query;      


              // Event handler to execute the OLAP query
              // after the cube completes initialization.
              private function runQuery(event:CubeEvent):void {
                  // Get cube.
                  var cube:IOLAPCube = IOLAPCube(event.currentTarget);
                  // Create a query instance.
                  var query:IOLAPQuery = getQuery(cube);
                  // Execute the query.
                  var token:AsyncToken = cube.execute(query);
                  // Setup handlers for the query results.
                  token.addResponder(new AsyncResponder(showResult, showFault));


              // Handle a query fault.
              private function showFault(result:Object, token:Object):void {
                  Alert.show("Error in query.");


              // Handle a successful query by passing the query results to
              // the OLAPDataGrid control..
              private function showResult(result:Object, token:Object):void {
                  if (!result) {
                      Alert.show("No results from query.");
                  myOLAPDG3.dataProvider= result as OLAPResult;           
          <mx:OLAPCube name="FlatSchemaCube" dataProvider="{dp}" id="myMXMLCube3" complete="runQuery(event);">
              <mx:OLAPDimension name="CustomerDim">
                  <mx:OLAPAttribute name="Customer" dataField="TITLE_NAME"/>
                  <mx:OLAPHierarchy name="CustomerHier" hasAll="true">
                      <mx:OLAPLevel attributeName="Customer"/>
              <mx:OLAPDimension name="ProductDim">
                  <mx:OLAPAttribute name="Product" dataField="CORP_SITE"/>
                  <mx:OLAPHierarchy name="ProductHier" hasAll="true">
                      <mx:OLAPLevel attributeName="Product"/>
              <mx:OLAPDimension name="QuarterDim">
                  <mx:OLAPAttribute name="HLMC" dataField="HLMC"/>
                  <mx:OLAPHierarchy name="QuarterHier" hasAll="true">
                      <mx:OLAPLevel attributeName="HLMC"/>
              <mx:OLAPMeasure name="Revenue"

               <mx:OLAPDataGrid id="myOLAPDG3" defaultCellString="-" textAlign="right" color="0x323232" width="100%" height="100%"/>

              <mx:ControlBar id="controls">       
              <mx:Button label="Pull Details" click="creationCompleteHandler3();"/>