2 Replies Latest reply on Sep 16, 2008 6:07 PM by ntsiii

    Httpservice to ArrayCollection problems

    Cr99 Level 1
      This is really bizarre but I have some code that was working previously and now is no longer working. I am using a servlet to output information in the following format:

      <system>
      <data>
      <name>Channel 1</name>
      <id>Rep1</id>
      </data>
      </system>

      But I am now getting a runtime error: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@20116041 to mx.collections.ArrayCollection



        • 1. Re: Httpservice to ArrayCollection problems
          Level 7

          "Cr99" <webforumsuser@macromedia.com> wrote in message
          news:gaoik2$mr7$1@forums.macromedia.com...
          > This is really bizarre but I have some code that was working previously
          > and now
          > is no longer working. I am using a servlet to output information in the
          > following format:
          >
          > <system>
          > <data>
          > <name>Channel 1</name>
          > <id>Rep1</id>
          > </data>
          > </system>
          >
          > But I am now getting a runtime error: Error #1034: Type Coercion failed:
          > cannot convert mx.utils::ObjectProxy@20116041 to
          > mx.collections.ArrayCollection
          >
          >
          >
          >
          >
          > public function initializeBrowser(evt:ResultEvent):void {
          > var arr:ArrayCollection = evt.result.system.data;
          > }
          >
          > <mx:HTTPService id="reportsList" result="initializeBrowser(event)"
          > useProxy="false"
          > method="GET" url="{dbURL}"/>

          Try setting the result format to Array. If that doesn't work, are you using
          Modules?

          HTH;

          Amy


          • 2. Re: Httpservice to ArrayCollection problems
            ntsiii Level 3
            This is probably the Object vs Array problem. The player is unable to differentiate between an array with a single element and an object. Test by adding another “data” node.

            I advise changing the default resultFormat to “e4x” and doing the conversion to ArrayCollection manually, instead of letting Flex do it for you. Or use XMLListCollection directly.

            Accepted best practice seems to be using resultFormat=”e4x” and building an ArrayCollection of strongly typed VOs.

            If you are committed to staying with the default resultFormat, you will need to inspect the event.result object to determine what it contains, and code for the two cases.

            Tracy