7 Replies Latest reply on May 20, 2010 5:20 PM by Flex harUI

    Casting Error Question

    ssardar

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@3be0f71 to generated.webservices.GridDataVO.

       

       

      I'm getting this error when I try this line:

       

      child = GridDataVO(gridData.getItemAt(index));

       

       

      gridData is defined as such:

       

       

       

      private var gridData:ListCollectionView = new ArrayCollection();

       

      and it is populated from my WebService with and Array of GridDataVO objects.

       

       

      Can anyone help?  I thought this was the proper way to cast.

       

       

      TIA.

        • 1. Re: Casting Error Question
          Flex harUI Adobe Employee

          It means that the GridDataVO is not registered as the class that maps to

          whatever came from the WebService.  Maybe the name is slightly off or

          there's a problem with registration.

          1 person found this helpful
          • 2. Re: Casting Error Question
            ssardar Level 1

            How would I register it?

             

            The class was generated from the Import WSDL feature.

             

             

            Or is there another way to access the 

             

            gridData.getItemAt(index);

             

            Object so that I may grab the date values in this object?

            • 3. Re: Casting Error Question
              Flex harUI Adobe Employee

              If you look at the .as file for the class, it should have registration code

              in it.

               

              You might want to examine the XML result from the Webservice to see if that

              class is properly in the result set.

               

              For now, you can just use the ObjectProxy.  Instead of casting to the VO,

              just case it as Object.  Of course, it won't give you compile time checking

              of property names.

              1 person found this helpful
              • 4. Re: Casting Error Question
                UbuntuPenguin Level 4

                [Deleted]

                My reply was soaked in weaksauce compared to the previous harUI's response.

                 

                Message was edited by: UbuntuPenguin

                 

                Message was edited by: UbuntuPenguin

                • 5. Re: Casting Error Question
                  ssardar Level 1

                  No worries UbuntuPenguin

                   

                  I really appreciate the time you took to respond.  Thanks.

                  • 6. Re: Casting Error Question
                    ssardar Level 1

                    Flex harUI,

                     

                    Casting to Object works just fine, thank you.

                     

                     

                    The XML result actually returns an ArrayCollection of Object Proxies when I ran it in debug mode.  I'm not sure if it's because of how I am calling my Webservice from Flex or if it's just what the WebService returns regardless.  Understanding this would be nice, as I have come across a few ways to call the WebService and am unsure which is best.  Plus I would like to have the message look exaclty as intended instead of using object proxies.

                     

                    On the Java end the WSDL was generated (bottom-up) by WAD 6.0 from my WebService entry point.

                     

                    Currently this is how I call the Web Service.

                     

                    <?xml version="1.0" encoding="utf-8"?>

                    <mx:Application

                     

                     

                    xmlns:mx="http://www.adobe.com/2006/mxml"

                    layout="

                    vertical"

                    creationComplete="initApp()" backgroundColor="

                    #11779D">

                     

                    <mx:Script>

                    <![CDATA[

                     

                    private function initApp():void

                    {

                    search();

                     

                    }

                     

                    private function search():void

                    {

                    pssSrv.getGridData();

                    }

                     

                    private function result(e:ResultEvent):void

                    {

                    gridData = e.result

                     

                    as ListCollectionView;

                     

                    }

                     

                     

                    private function fault(e:FaultEvent ) : void

                    {

                    Alert.show(e.fault.message);

                    }

                     

                    ]]>

                     

                    </mx:Script>

                     

                     

                     

                    <mx:WebService id="pssSrv"

                    wsdl="

                    wsdl destination" showBusyCursor="true">

                     

                     

                    <mx:operation

                    name="

                     

                    getGridData"

                    result="result(event)"

                    fault="fault(event)"

                    />

                     

                     

                    </mx:WebService>

                     

                     

                     

                     

                     

                     

                    If the method of how I am calling the service is forcing this ObjectProxy issue please let me know.  Thanks.

                    • 7. Re: Casting Error Question
                      Flex harUI Adobe Employee

                      I don't think it is the way the WebService is being used.  I think the key

                      as to whether it returns ObjectProxy or your intended class is based on the

                      class's fully qualified name and how it maps to the XML in the data returned

                      from the server.  Flex code will parse the XML and try to map the XML to

                      known classes.

                       

                      You can set resultFormat="e4x" and dump the result's toXMLString to see what

                      the XML looks like and compare it to the WSDL and the ActionScript class.

                      There should be some code somewhere that dictates the XML tag name for your

                      ActionScript class.