8 Replies Latest reply on Jul 10, 2009 8:10 AM by ma.tze

    How to convert evt.result value into ArrayCollection

    Raghuvasa Level 1

      Hi All,

               i am getting object from databse as evt.result in ActionScript method.

               i have to assign this evt.result to ArrayCollection variable.

       

               [Bindable]
              public var dp:ArrayCollection;

       

              this is dp is ArrayCollection variable. i want to assign evt.result into dp

       

              How can i do it. any one can help me.

       

      Thanks

      Raghu.

        • 1. Re: How to convert evt.result value into ArrayCollection
          _Natasha_ Level 4

          Hi,

          what is the type of this result?

           

          In result event handler you should write

          dp = new ArrayCollection(event.result); // if event.result is an Array

          dp = ArrayCollection(event.result); // if event.result is already an ArrayCollection.

           

          Also you can bind with lastResult (if data is from HTTPService)

          • 2. Re: How to convert evt.result value into ArrayCollection
            Raghuvasa Level 1

            Hi Natasha,

             

            i am calling a method getData in java class through Remote Object like this way

             

            <mx:RemoteObject id="empservice" showBusyCursor="true" destination="emp">
                        <mx:method name="getData" result="resultHandler(event)" />
                </mx:RemoteObject>

             

            //--------Action Script methods.

             

             

                  function dbConnection():void{
                        empservice.getOperation('getData').send();
                    }
               
                    function resultHandler(evt:ResultEvent):void{
                       
                        chart.dataProvider = evt.result;
                        ca1.dataProvider = evt.result;
                    }

             

            this is the way  i am doing .

            In resultHandler i am assinging to chart.dataProvider but i want  to assign to ArrayCollection variable.

            How can i do it.

             

            thanks

            Raghu.

            • 3. Re: How to convert evt.result value into ArrayCollection
              _Natasha_ Level 4

              Chart dataProvider can be Array and ArrayCollection, so I can't understand what type do you have. By default from RemoteObject data returned as Array.

               

              So first try

              dp = new ArrayCollection(event.result);

               

              But also you can try

              dp = ArrayCollection(event.result);

              If event.result is Array dp will be null.

              • 4. Re: How to convert evt.result value into ArrayCollection
                Raghuvasa Level 1

                Hi Natasha,

                 

                                   Thanks for your replies. pls dont hesitate for my questons becoz i am new to this.

                 

                as u said that i have assigned dp:ArrayCollection = new ArrayCollection(evt.result); but it is showing error

                Implicit coercion of a value with static type Object to a possibly unrelated type Array.

                 

                 

                in resultHanlder

                 

                instead of assigning evt.result to chart.dataProvider i want to assign evt.result to dp. dp is an ArrayCollection variable and i wan to assign like this way

                  <mx:ColumnChart id="chart"   showDataTips="true"  dataProvider="dp">

                 

                how to capture the result returned by the Remote object. and how to assign it to dp. dont forget to see i have mentioned return type as void for action script methods. is there any change pls let me know.

                 

                this is my application

                 

                <?xml version="1.0"?>
                <!-- charts/DrillDownWithEffects.mxml -->
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" width="100%" initialize="dbConnection();">


                   <mx:RemoteObject id="empservice" showBusyCursor="true" destination="emp">
                            <mx:method name="getData" result="resultHandler(event)" />
                    </mx:RemoteObject>

                 

                    <mx:Script><![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.charts.HitData;
                        import mx.charts.events.ChartItemEvent;
                        import mx.rpc.events.ResultEvent;
                 
                       
                        [Bindable]
                        public var dp:ArrayCollection;
                    
                       function dbConnection():void{
                             empservice.getOperation('getData').send();
                        }
                   
                        function resultHandler(evt:ResultEvent):void{
                            chart.dataProvider = evt.result;
                            ca1.dataProvider = evt.result;
                        }

                 


                    ]]></mx:Script>

                 

                   
                    <mx:Panel id="p1" title="Net Worth">
                         <mx:ColumnChart id="chart"   showDataTips="true" >
                            <mx:series>
                                <mx:ColumnSeries id="cs1"
                                    displayName="States"
                                    yField="States"
                                    xField="States"/>
                                <mx:ColumnSeries
                                    xField="States"
                                    yField="date"
                                    displayName="date" />
                           
                            </mx:series>       
                            <mx:horizontalAxis>
                                <mx:CategoryAxis id="ca1" categoryField="States"/>
                            </mx:horizontalAxis>
                        </mx:ColumnChart>
                       
                        <mx:Legend id="myLegend" dataProvider="{chart}"/>
                    </mx:Panel>

                 

                </mx:Application>

                • 5. Re: How to convert evt.result value into ArrayCollection
                  rgadiparthi Level 2

                   

                   

                  Seems your service returns object,

                   

                  Here you can do two things

                  1. Change the service(getOperation('getData')) return type to Array or ArrayCollection.

                   

                  or

                   

                  2. Loop thru your object and create a array or arraycollection by yourself.

                   

                   


                  • 6. Re: How to convert evt.result value into ArrayCollection
                    Raghuvasa Level 1

                    Hi ,

                     

                           Where can i change the return type. and how can i change the return type.

                     

                    Thanks

                    Raghu.

                    • 7. Re: How to convert evt.result value into ArrayCollection
                      rgadiparthi Level 2

                      if you have access to service code you can change for the method you are calling.

                       

                      there you need to tweek your code to return Array instead of Object.

                      • 8. Re: How to convert evt.result value into ArrayCollection
                        ma.tze Level 1

                        Hi,

                         

                         

                        does this help?

                         

                        dp=event.result as ArrayCollection;

                         

                        By!

                         

                        Martin Zach