10 Replies Latest reply on Oct 18, 2008 4:25 PM by Karzons

    HTTService and ArrayCollection variable

      First of all - thanks for these turorials - they´re great.
      But as a beginner its easy to do something wrong.
      So I still appreciate the source code, so we can speed up the learning curve an dont struggle
      with small details like to many blank spaces on so on..

      I´ve done the excercise with HTTService over and over.
      I have debugging and all that, disable all firewalls but still cant manage to load the xml-file into the DataGrid.
      The files and directories are exact as in your tutorials.
      But only a blank page i displayed

      Here´s what the debbuger tells me:
      "..cannot convert mx.utils::ObjectProxy@29d1ee1 to mx.collections.ArrayCollection."

      What could probably be wrong?


      Here´s the code:
        • 1. Re: HTTService and ArrayCollection variable
          SujitG Level 2
          Hi,

          I think the event.result.employees.employee is returning an object of the type ObjectProxy, which you are trying to assign to ArrayCollection. Try to share the XML you are using, we will try to get it working.

          Hope this helps.
          • 2. Re: HTTService and ArrayCollection variable
            Here´s the XML-file:
            • 3. Re: HTTService and ArrayCollection variable
              Vinay Soni
              Hi,

              Looks like the error message:

              "..cannot convert mx.utils::ObjectProxy@29d1ee1 to mx.collections.ArrayCollection."

              is trying to say that ObjectProxy is a single Employee element in the XML and can't be assigned to a collection.

              so probably, you can try:

              employeeData = event.result.employees;

              This appears to be more logical because:

              private var employeeData:ArrayCollection; is a collection and event.result.employees is a collection of Employees

              Try and it may just work,

              Vinay
              1 person found this helpful
              • 4. Re: HTTService and ArrayCollection variable
                Vinay Soni Level 1
                Hi,

                Looks like the error message:

                "..cannot convert mx.utils::ObjectProxy@29d1ee1 to mx.collections.ArrayCollection."

                is trying to say that ObjectProxy is a single Employee element in the XML and can't be assigned to a collection.

                so probably, you can try:

                employeeData = event.result.employees;

                This appears to be more logical because:

                private var employeeData:ArrayCollection; is a collection and event.result.employees is a collection of Employees

                Try and it may just work,

                Vinay
                1 person found this helpful
                • 5. Re: HTTService and ArrayCollection variable
                  Vinay Soni Level 1
                  sorry clicked the button two times. Is there a solution for this in Flex?
                  • 6. HTTService and ArrayCollection variable
                    >so probably, you can try:

                    >employeeData = event.result.employees;


                    Thanks, but it does´nt work either.



                    The tutorial on Day 2 about "creating custom event classes" was perhaps not the most
                    pedagogical example in thesse series of tutorials. But I hope the rest is better.

                    • 7. Re: HTTService and ArrayCollection variable
                      rad-pol
                      Try to add another employee data in xml
                      It seems that one is not enough :P
                      1 person found this helpful
                      • 8. Re: HTTService and ArrayCollection variable
                        rsadwick
                        Hello highlander_1,

                        I managed to get your example working with a few modifications. I datatyped employeeData as XMLListCollection and added the resultFormat property in the HTTPService to e4X. Using e4X and the XMLList collection will allow you to easily populate the dataGrid. Take notice in the code below, I used

                        quote:

                        <mx:DataGridColumn dataField="firstname" headerText="First Name"/>


                        The dataField property is the <firstname> tag in the XML file. The headerText property is what the column will be called. You can add more of these. In the example I edited for you, I only display three (firstname, lastname, email).

                        You were getting the ObjectProxy datatype by not casting the ArrayCollection. For example:
                        quote:

                        myDataStuff = event.result.employee as ArrayCollection;


                        In this application, I copied your XML file into my project in a data folder, here is the application file:

                        quote:

                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
                        creationComplete="init()">

                        <mx:Script>
                        <![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.collections.XMLListCollection;
                        import mx.rpc.events.ResultEvent;

                        [Bindable]
                        private var employeeData:XMLListCollection = new XMLListCollection();

                        private function init():void
                        {
                        employeeService.send();
                        }

                        private function resultHandler(event:ResultEvent):void
                        {
                        //We're going to wrap the source with the XMLList.
                        var employeeResultData:XMLList = new XMLList();
                        employeeResultData = event.result.employee;
                        employeeData.source = employeeResultData;
                        }

                        ]]>
                        </mx:Script>
                        <!--HTTPService: set the resultFormat to e4x.-->
                        <mx:HTTPService id="employeeService" url="data/testData.xml"
                        result="resultHandler(event)" resultFormat="e4x"/>

                        <!--DataGrid. Add more column to display by creating more DataGridColumn tags-->
                        <mx:DataGrid id="employeeGrid"
                        dataProvider="{employeeData}"
                        width="480">
                        <mx:columns>
                        <mx:DataGridColumn dataField="firstname" headerText="First Name"/>
                        <mx:DataGridColumn dataField="lastname" headerText="Last Name"/>
                        <mx:DataGridColumn dataField="email" headerText="Email Address"/>
                        </mx:columns>
                        </mx:DataGrid>
                        </mx:Application>



                        Hope this helps you,

                        Ryan



                        • 9. Re: HTTService and ArrayCollection variable
                          rsadwick
                          Honest
                          - I went tired of this exercise and did work on some other stuff for a while.

                          But your solution works - great, now I can go further with the other exercises.

                          • 10. Re: HTTService and ArrayCollection variable
                            Karzons Level 1
                            rsadwick, I think you are right here