5 Replies Latest reply on Dec 6, 2007 8:48 AM by m_hartnett

    Error Loading an ArrayCollection

    ChiefRocka00 Level 1
      I have an array collection that I load, however I get an error when there is only one record returned. How do I prevent this error from occuring and get the results I expect. The error I get is:

      Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@403fbc1 to mx.collections.ArrayCollection

      Thanks in advance
      Tedd
        • 1. Re: Error Loading an ArrayCollection
          Level 7
          How are you loading the data?

          How are you processing the result?




          Hello ChiefRocka00,

          > I have an array collection that I load, however I get an error when
          > there is only one record returned. How do I prevent this error from
          > occuring and get the results I expect. The error I get is:
          >
          > Error #1034: Type Coercion failed: cannot convert
          > mx.utils::ObjectProxy@403fbc1 to mx.collections.ArrayCollection
          >
          > Thanks in advance
          > Tedd


          • 2. Re: Error Loading an ArrayCollection
            ChiefRocka00 Level 1
            I have an array collection defined that gets populated with XML results received from an HTTPService request. Here is my code:

            [Bindable] public var myData:ArrayCollection;
            [Bindable] public var strDateSelected:String = "";

            private function returnedDbEvents(event:ResultEvent):void {
            if ( event.result.dbGridData != null ) {
            myData = ArrayCollection(event.result.dbGridData.eventData);
            }
            }

            <mx:HTTPService id="getEvents"
            url=" http://www.someUrl.php"
            useProxy="false"
            method="POST"
            result="returnedDbEvents(event)">
            <mx:request xmlns="">
            <dateSelected>{strDateSelected.valueOf()}</dateSelected>
            </mx:request>
            </mx:HTTPService>

            whenever there is only one record returned I get the error
            • 3. Re: Error Loading an ArrayCollection
              Tariq Ahmed [ACP]
              What if you go:

              myData = new ArrayCollection(event.result.dbGridData.eventData);
              • 4. Re: Error Loading an ArrayCollection
                ChiefRocka00 Level 1
                if you do that as the result of the HTTPService request you run into a problem if there are no records returned. That's why I made the function call to check for null so I got past that issue, but now I have an issue if there is only one record returned.
                • 5. Re: Error Loading an ArrayCollection
                  m_hartnett Level 3
                  If you have only a single object returned it is returned as an Object not ArrayCollection. You need to check for that condition.


                  if(rpcEvent.result.dbConns.dbConnItem is ArrayCollection)
                  model.dbConnAC = rpcEvent.result.dbConns.dbConnItem as ArrayCollection;
                  else
                  model.dbConnAC.addItem( rpcEvent.result.dbConns.dbConnItem );