WebMapUtil error thrown when there is no internet connectivity

844
2
03-19-2012 05:11 AM
SilviaPetcu
New Contributor
If there is no internet connectivity and try to load a Web Map the next error is thrown:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.rpc.events::FaultEvent@13a5a301 to com.esri.ags.events.LayerEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.esri.ags.webmap::WebMapUtil/faultHandler()
at mx.rpc::AsyncResponder/fault()
at com.esri.ags.tasks::BaseTask/handleFault()
at Function/com.esri.ags.tasks:BaseTask/esri_internal:sendURLVariables2/com.esri.ags.tasks:fault()
at mx.rpc::Responder/fault()
at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyFault()
at mx.rpc.events::FaultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()
at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()
at mx.rpc::Responder/fault()
at mx.rpc::AsyncRequest/fault()
at DirectHTTPMessageResponder/errorHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

My WebMapUtil object has a listener to a FaultEvent but the event is never triggered.
I'm using agslib-2.5-2011-11-30.swc library.
Tags (2)
0 Kudos
2 Replies
IvanBespalov
Occasional Contributor III
Silvia, no.

If I disable my network device i recieve this error message:
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.arcgis.com/sharing/content/items/78e9ed6c172a43719e2114cfb7f6d306?f=json"]. URL: http://www.arcgis.com/sharing/content/items/78e9ed6c172a43719e2114cfb7f6d306?f=json"] 
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler() 
at mx.rpc::Responder/fault() 
at mx.rpc::AsyncRequest/fault() 
at DirectHTTPMessageResponder/errorHandler() 
at flash.events::EventDispatcher/dispatchEventFunction() 
at flash.events::EventDispatcher/dispatchEvent() 
at flash.net::URLLoader/onComplete()


You need to search in adobe forums about: "event listeners", "event dispatchers".

cannot convert mx.rpc.events::FaultEvent@13a5a301 to com.esri.ags.events.LayerEvent


just fill the difference:

wrong code:
var wmUtil:WebMapUtil = new WebMapUtil();
wmUtil.addEventListener(FaultEvent.FAULT, onWebMapUtilFault, false, 0, true);

protected function onWebMapUtilFault(event:LayerEvent):void // wrong event type
{
    //
}

/*
TypeError: Error #1034: Type Coercion failed: cannot convert mx.rpc.events::FaultEvent@ad35f81 to com.esri.ags.events.LayerEvent.
...
...
*/

working code:
var wmUtil:WebMapUtil = new WebMapUtil();
wmUtil.addEventListener(FaultEvent.FAULT, onWebMapUtilFault, false, 0, true);

protected function onWebMapUtilFault(event:FaultEvent):void
{
    trace(event.fault.getStackTrace());
}


Sample:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx"
      xmlns:ags="http://www.esri.com/2008/ags">

 <!-- Adobe Flex SDK 4.5.1 -->
 <!-- ArcGIS API for Flex 2.5 -->
        <!-- http://web.zone.ee/bespiva/webmaputil/ -->
 
 <s:layout>
  <s:HorizontalLayout gap="5"
       paddingBottom="10"
       paddingLeft="10"
       paddingRight="10"
       paddingTop="10" />
 </s:layout>
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Map;
   import com.esri.ags.events.WebMapEvent;
   import com.esri.ags.webmap.WebMapUtil;
   
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   import mx.rpc.AsyncResponder;
   import mx.rpc.Fault;
   
   protected function onPanelCreationComplete(event:FlexEvent):void
   {
    var targetPanel:Panel = event.target as Panel;
    
    var wmUtil:WebMapUtil = new WebMapUtil();
    
    switch (targetPanel.id)
    {
     case (panel1.id):
     {
      wmUtil.createMapById("69f7b98f49db4becb44ac2de3aa37dd9", 
       new AsyncResponder(onCreateMapByIdComplete, onFault, targetPanel.id));
      break;
     }
     case (panel2.id):
     {
      wmUtil.createMapById("f3b0db715d9148f7a4d3b4f8159b90b5", 
       new AsyncResponder(onCreateMapByIdComplete, onFault, targetPanel.id));
      break;
     }
     case (panel3.id):
     {
      wmUtil.createMapById("b3b981c496d443749fdc8661f9e38e65", 
       new AsyncResponder(onCreateMapByIdComplete, onFault, targetPanel.id));
      break;
     }
     case (panel4.id):
     {
      wmUtil.createMapById("78e9ed6c172a43719e2114cfb7f6d306", 
       new AsyncResponder(onCreateMapByIdComplete, onFault, targetPanel.id));
      break;
     }
    }  
   }
   
   protected function onCreateMapByIdComplete(event:WebMapEvent, token:Object = null):void
   {
    if (event.errors.length > 0)
    {
     for (var i:int; i < event.errors.length; i++)
     {
      trace(event.errors);
     }
     return;
    }
    
    var map:Map = event.map as Map;
    if (map != null)
    {
     switch (token.toString())
     {
      case panel1.id:
      {
       panel1.removeAllElements();
       panel1.addElement(map);
       break;
      }       
      case panel2.id:
      {
       panel2.removeAllElements();
       panel2.addElement(map);
       break;
      }
      case panel3.id:
      {
       panel3.removeAllElements();
       panel3.addElement(map);
       break;
      }
      case panel4.id:
      {
       panel4.removeAllElements();
       panel4.addElement(map);
       break;
      }
     }
    }
   }
   
   protected function onFault(fault:Fault, token:Object = null):void
   {
    trace(fault.getStackTrace());
    Alert.show(fault.message.toString(), "Fault");
   }

  ]]>
 </fx:Script> 
 
 <s:VGroup gap="5" 
     width="100%" 
     height="100%">
  
  <s:Panel id="panel1" 
     title="Top-Left panel"
     width="100%" 
     height="100%"
     creationComplete="onPanelCreationComplete(event)">
   
  </s:Panel>
  
  <s:Panel id="panel2" 
     title="Bottom-Left panel"
     width="100%" 
     height="100%"
     creationComplete="onPanelCreationComplete(event)">
   
  </s:Panel>
  
 </s:VGroup>
 
 <s:VGroup gap="5" 
     width="100%" 
     height="100%">
  
  <s:Panel id="panel3" 
     title="Top-Right panel"
     width="100%" 
     height="100%"
     creationComplete="onPanelCreationComplete(event)">
   
  </s:Panel>
  
  <s:Panel id="panel4" 
     title="Bottom-Right panel"
     width="100%" 
     height="100%"
     creationComplete="onPanelCreationComplete(event)">
   
  </s:Panel>
  
 </s:VGroup>
 
</s:Application>
0 Kudos
SilviaPetcu
New Contributor
Thank you Ivan for your answer.
It make sense.
0 Kudos