School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,464 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,650 people online right now. Registration is fast and FREE... Join Now!




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

 

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

cy163

3 Jul, 2009 - 05:10 AM
Post #1

New D.I.C Head
*

Joined: 29 Jun, 2009
Posts: 2

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()


This post has been edited by cy163: 3 Jul, 2009 - 05:11 AM

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:25AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month