0 Replies Latest reply on Sep 25, 2009 11:03 AM by agorman_co

    TypeError: Error #1034: Type Coercion failed

    agorman_co Level 1

      Hello experts...


      I have looked around the forums and seen many occurrences of this coercion error, but the solution I have seen do not fix my problem, which has somewhat complex, yet predictable, behavior.


      I have an application that displays some web service results in a DataGrid. You can drill down by double-clicking a record, which launches another application using a swfloader. From there, the use can perform subsequent service calls, which all work fine under most circumstances. The problem occurs when you launch a second drill down BEFORE performing particular service calls in the first drill down and then return to the first drill down and perform a service call. The problem is in casting the result that are returned. Here is an example error message. I have included the whole stack trace in case it might help. I'm not sure if this is related to the data binding. Below the stack trace I have included two scenarios, one that works fine, and one that doesn't.


      TypeError: Error #1034: Type Coercion failed: cannot convert org.unavco.dai.explorer.services::FundingItem@2bfc6d91 to org.unavco.dai.explorer.services.FundingItem.
          at org.unavco.dai.explorer.views::Pi/set funding()[/Users/gorman/Documents/EclipseWorkspace/drill_down/org/unavco/dai/explorer/vie ws/Pi.mxml:31]
          at <anonymous>()[/Users/gorman/Documents/EclipseWorkspace/drill_down/Explorer.mxml:352]
          at Function/http://adobe.com/AS3/2006/builtin::call()
          at mx.binding::Binding/innerExecute()[/Users/gorman/Documents/EclipseWorkspace/lib/FlexBuild er/sdks/3.1.0/frameworks/projects/framework/src/mx/binding/Binding.as:375]
          at Function/http://adobe.com/AS3/2006/builtin::apply()
          at mx.binding::Binding/wrapFunctionCall()[/Users/gorman/Documents/EclipseWorkspace/lib/FlexB uilder/sdks/3.1.0/frameworks/projects/framework/src/mx/binding/Binding.as:287]
          at mx.binding::Binding/execute()[/Users/gorman/Documents/EclipseWorkspace/lib/FlexBuilder/sd ks/3.1.0/frameworks/projects/framework/src/mx/binding/Binding.as:230]
          at mx.binFri Sep 25 16:00:07 2009 UTCGenericRemotingService: resultsListener(): Destination: dai-funding
      ding::Binding/watcherFired()[/Users/gorman/Documents/EclipseWorkspace/lib/FlexBuilder/sdks /3.1.0/frameworks/projects/framework/src/mx/binding/Binding.as:396]
          at mx.binding::Watcher/notifyListeners()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\b inding\Watcher.as:299]
          at mx.binding::PropertyWatcher/eventHandler()[E:\dev\3.1.0\frameworks\projects\framework\src \mx\binding\PropertyWatcher.as:327]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at org.unavco.dai.search::GenericRemotingService/set results()[/Users/gorman/Documents/EclipseWorkspace/search/org/unavco/dai/search/GenericRe motingService.as:34]
          at org.unavco.dai.search::GenericRemotingService/handleResponse()[/Users/gorman/Documents/Ec lipseWorkspace/search/org/unavco/dai/search/GenericRemotingService.as:80]
          at org.unavco.dai.search::AbstractRemotingService/handleResult()[/Users/gorman/Documents/Ecl ipseWorkspace/search/org/unavco/dai/search/AbstractRemotingService.as:111]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.rpc::AbstractService/dispatchEvent()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\A bstractService.as:237]
          at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.1.0\frameworks\pro jects\rpc\src\mx\rpc\AbstractOperation.as:202]
          at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.1.0\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:193]
          at mx.rpc::Responder/result()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:4 3]
          at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:74]
          at NetConnectionMessageResponder/resultHandler()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx \messaging\channels\NetConnectionChannel.as:491]
          at mx.messaging::MessageResponder/result()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\messa ging\MessageResponder.as:199]


      The strange thing is that it seems to be saying that it cannot cast a FundingItem to a FundingItem. What is also strange is that the cast works in most situations. Here are some examples:


      Scenario 1 works fine:

      a) launch drill down A and perform a service call

      b) launch drill down B while A is still running and perform a service with B


      Scenario 2 casting exception:

      a) launch drill down A

      b) launch drill down B while A is still running

      c) switch focus to drill down A and perform a service call (I get an error casting the results).


      When I run the code in the debugger, the object appears to be the class I am expecting,but it does not pass the "is" test. Here is some code and the resulting trace output. (I tested it with a different service that I have modified to catch the error so we are now lookig at ArchivedFilesItem instead of FundingItem)


      trace("In Files set files: Expecting " +
          getDefinitionByName("org.unavco.dai.explorer.services.ArchivedFilesItem") +
          " and found " + getQualifiedClassName(_files.getItemAt(i)));


      if (_files.getItemAt(i) is ArchivedFilesItem) {
          trace("*is* ArchivedFilesItem = TRUE"); 
      } else {
          trace("*is* ArchivedFilesItem = FALSE"); 

      var record:ArchivedFilesItem;
      try {
          ArchivedFilesItem= ArchivedFilesItem(_files.getItemAt(i));
      } catch (e:Error) {
          trace("Error: " + e);


      Scenario 1 (discribed above) works fine and produces this output:

      In Files set files: Expecting [class ArchivedFilesItem] and found org.unavco.dai.explorer.services::ArchivedFilesItem

      *is* ArchivedFilesItem = TRUE


      Scenario 2 (discribed above) produces this output:

      In Files set files: Expecting [class ArchivedFilesItem] and found org.unavco.dai.explorer.services::ArchivedFilesItem

      *is* ArchivedFilesItem = FALSE

      Error: TypeError: Error #1034: Type Coercion failed: cannot convert org.unavco.dai.explorer.services::ArchivedFilesItem@2ae72e09 to org.unavco.dai.explorer.services.ArchivedFilesItem.


      This seems bazaar!


      As I have seen suggested in other threads, I have tried explicitly declaring and instantiating objects of this type in both the main application that launches the drill down as well as in the drill down itself.


      I have also tried disabling the load-externs option for compiling the drill down (I was sort of grasping at straws).


      Can any of the experts out there suggest a direction for me to investigate? I would really like to understand this curious error.