TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCol

By cy163 | Jul 3, 2009

actionscript3

I have a MXML file as follows

Code:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="http.send();initApp()"> 
    <mx:Script> 
        <![CDATA[ 
            import mx.rpc.events.ResultEvent; 
            import mx.collections.ArrayCollection; 
            [Bindable] 
            public var myData:ArrayCollection; 
           
            private function initApp():void {
                                this.http.send();
                        }
                       
                       
            public function resultHandler(event:ResultEvent):void{ 
//                        error.text = event.result as String; 
                        myData = new ArrayCollection(event.result.shuju.shuiguo);           
                }

        ]]> 
    </mx:Script>

  <!–<mx:HTTPService id="http" url="http://localhost:8080/web.xml" useProxy="false" result="resultHandler(event)"/>–> 
    <mx:HTTPService id="http" url="http://localhost:8080/web.xml" useProxy="false" result="myData=ArrayCollection(http.lastResult.shuju.shuiguo)"/>
   

    <mx:DataGrid dataProvider="{myData}"
x="80" y="141" width="262" height="92"
id="shippingOptionsList"
editable="false" enabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Task1" dataField="Task1" />
<mx:DataGridColumn headerText="Task2" dataField="Task2" />
</mx:columns>
</mx:DataGrid>

</mx:Application>


it works well. Howeve, when I replace

Code:


<mx:HTTPService id="http" url="http://localhost:8080/web.xml"
useProxy="false"
result="myData=ArrayCollection(http.lastResult.shuju.shuiguo)"/>


with

Code:


<mx:HTTPService id="http" url="http://localhost:8080/web.xml"
useProxy="false" result="resultHandler(event)"/>


i.e., using resultHandler(event) to handle the received data. I got the following error messages. I could not figure out why? Please help.

Code:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@36f5741 into Array。
        at TEST2/resultHandler()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\TEST2\src\TEST2.mxml:17]
        at TEST2/__http_result()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\TEST2\src\TEST2.mxml:23]
        at flash.events::EventDispatcher/dispatchEventFunction()
        at flash.events::EventDispatcher/dispatchEvent()
        at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:290]
        at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
        at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
        at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
        at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403]
        at flash.events::EventDispatcher/dispatchEventFunction()


actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0