3 Replies Latest reply on Oct 25, 2007 11:05 AM by Gregory Lafrance

    Adding Variables to ArrayCollection

    GeorgeWS Level 1
      I cant get the Varaibles into my addItem.

      This works if I hardcode the qCUSN05:50

      public function handleQueryResult2(event:ResultEvent):void{
      myChart=event.result as ArrayCollection;
      myChart.addItem({qBRAD53:"Competition", qCUSN05:50, qCATG53:01});
      }

      But this does NOT:qCUSN05:sResult6

      [Bindable]
      public var sResult6:Object;

      public function handleStringResult2(event:ResultEvent):void{
      sResult6=50;
      }

      public function handleQueryResult2(event:ResultEvent):void{
      myChart=event.result as ArrayCollection;
      myChart.addItem({qBRAD53:"Competition", qCUSN05:sResult6, qCATG53:01});
      }

      Any Thoughts? Thanks

      George
        • 1. Re: Adding Variables to ArrayCollection
          HouserDesign
          At first you type your sResult6 as an Object, and then you try to assign it as a Number? Maybe you need to type your sResult6 as a Number in your var definition?
          • 2. Re: Adding Variables to ArrayCollection
            GeorgeWS Level 1
            Thanks for the reply, I did try Number also String and Object. It doesnt seem to want to show the var. Any other thoughts?

            George
            • 3. Re: Adding Variables to ArrayCollection
              Gregory Lafrance Level 6
              I think this is a timing issue. You are setting the variable in a ResultEvent handler, and also using the variable in a ResultEvent handler. Maybe the variable is not set yet. Uncomment the line of the following code setting the variable in the other ResultEvent handler and you will see.

              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init()">
              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.rpc.http.HTTPService;
              import mx.rpc.events.ResultEvent;
              import mx.rpc.events.FaultEvent;
              import mx.collections.ArrayCollection;

              private var service:HTTPService;

              [Bindable]
              public var myChart:ArrayCollection = new ArrayCollection();
              [Bindable]
              public var sResult6:Object;

              //This works if I hardcode the qCUSN05:50
              public function handleQueryResult(event:ResultEvent):void{
              myChart.addItem({qBRAD53:"Competition", qCUSN05:50, qCATG53:01});
              }

              //But this does NOT:qCUSN05:sResult6. I cant get the Varaibles into my addItem.
              public function handleStringResult2(event:ResultEvent):void{
              sResult6=50;
              }

              public function handleQueryResult2(event:ResultEvent):void{
              // sResult6=50;
              myChart.addItem({qBRAD53:"Competition", qCUSN05:sResult6, qCATG53:01});
              }

              public function init():void {
              myChart.addItem({qBRAD53:"Test1", qCUSN05:10, qCATG53:00});
              }

              // This function just serves to fire a ResultEvent object.
              // We don't actually use the result.
              public function useHttpService(parameters:Object):void {
              service = new HTTPService();
              service.url=" http://weblogs.macromedia.com/mchotin/index.xml";
              service.addEventListener("result", handleQueryResult);
              service.addEventListener("result", handleQueryResult2);
              service.addEventListener("result", handleStringResult2);
              service.addEventListener("fault", httpFault);
              service.send();
              }

              public function httpFault(event:FaultEvent):void {
              var faultstring:String = event.fault.faultString;
              Alert.show(faultstring);
              }
              ]]>
              </mx:Script>
              <mx:Button label="Use Service" click="useHttpService('Greg')"/>
              <mx:DataGrid dataProvider="{myChart}" width="100%" height="50%"/>
              <mx:TextArea id="txtArea" width="100%" height="50%"/>
              </mx:Application>