1 Reply Latest reply on Jul 19, 2009 1:16 PM by Flex harUI

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

    Vitor Wsis Level 1

      I have a MXML file as follows:
      <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();"
      paddingLeft="15" paddingRight="15" paddingBottom="15" height="100%" width="100%"
      hideEffect="{dissolveOut}" showEffect="{dissolveIn}" >
      <mx: Dissolve id="dissolveOut" duration="200" alphaFrom="1.0" alphaTo="0.0"/>
      <mx: Dissolve id="dissolveIn" duration="200" alphaFrom="0.0" alphaTo="1.0"/>   

      <mx:Metadata>
      [Event(name="selectUserEvent", type="events.UserEvent")]
      </mx:Metadata>
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import events.UserEvent;
      import valueObjects.UserObject;
      import mx.events.ListEvent;
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;


      [Bindable]
      public var userData:ArrayCollection;

      private function init():void{
      usersXML.send();
      }


      private function resultHandler(event:ResultEvent):void {
      userData = new ArrayCollection();
      var userResultData:ArrayCollection = event.result.utilizadores.utilizador;
      var resultLength:Number = userResultData.length;

      if(resultLength>0)

      for(var i:Number=0; i<resultLength; i++){
      var tempUserObject:UserObject = new UserObject();
      tempUserObject.id = userResultData.getItemAt(i).id;
      tempUserObject.nome = userResultData.getItemAt(i).nome;
      tempUserObject.username = userResultData.getItemAt(i).username;
      tempUserObject.pass = userResultData.getItemAt(i).pass;
      tempUserObject.tipo = userResultData.getItemAt(i).tipo;
      tempUserObject.ulogin = userResultData.getItemAt(i).ulogin;
      tempUserObject.data = userResultData.getItemAt(i).data;
      tempUserObject.activo = userResultData.getItemAt(i).activo;
      userData.addItem(tempUserObject);
      }
      //Alert.show(usersXML.lastResult.toString());
      }

      private function itemClickHandler(event:ListEvent):void{
      var userData:UserObject;
      userData = event.itemRenderer.data as UserObject;
      var userEventObject:UserEvent = new UserEvent("selectUserEvent",userData);
      dispatchEvent(userEventObject);
      }

      ]]>
      </mx:Script>

      <mx:HTTPService id="usersXML"
      url="../PHP/users.php?op=list"
      result="resultHandler(event)" showBusyCursor="true"/>

      <mx:Canvas height="69" width="399">
      <mx:Image source="../images/app/users.png" x="0" y="7"/>
      <mx:Label text="Listagem" fontSize="12" fontFamily="Verdana" fontWeight="bold" color="#7C7C7C" x="54" y="19"/>
      <mx:Label text="Utilizadores" fontSize="12" fontFamily="Verdana" fontWeight="normal" color="#7C7C7C" x="54" y="36"/>
      </mx:Canvas>

      <mx: DataGrid id="gridUsers" dataProvider="{userData}" x="10" y="43" width="100%" height="100%"
      alternatingItemColors="[#FFFFFF, #CCCCCC]"
      itemClick="itemClickHandler(event)">
      <mx:columns>
      <mx: DataGridColumn headerText="Nome Utilizador" dataField="nome"/>
      <mx: DataGridColumn headerText="UserName" dataField="username"/>
      <mx: DataGridColumn headerText="Tipo" dataField="tipo"/>
      <mx: DataGridColumn headerText="Último Login" dataField="ulogin"/>
      <mx: DataGridColumn headerText="Criado em" dataField="data"/>
      <mx: DataGridColumn headerText="Activo" dataField="activo"/>
      </mx:columns>
      </mx: DataGrid>

      </mx:VBox>

      it works well. Howeve, when I have 0 or 1 record gives-me this error:

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@47af5e1 to mx.collections.ArrayCollection.
      at components::listaUtilizadores/resultHandler()[C:\wamp\www\Gestao\src\components\listaUtil izadore  s.mxml:33]
      at components::listaUtilizadores/__usersXML_result()[C:\wamp\www\Gestao\src\components\lista Utilizadore  s.mxml:65]
      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\framewor ks\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\s rc\mx\ messaging\channels\DirectHTTPChannel.as:403]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()