Select to view content in your preferred language

com.esri.ags.symbols.TextSymbol is not TextSymbol in FlexViewer widget

2400
2
08-30-2010 12:41 PM
JonathanNagy
New Contributor
Hello.  I am in the process of writing a widget to save annotations to SVG and its mostly working except that the TextSymbol graphic symbols created by the FlexViewer's Draw widget are not recognized by their actual type, i.e. TextSymbol. 

If I have a text graphic named textGraphic, "textGraphic.symbol is TextSymbol" evaluates to false even though the type of textGraphic.symbol is com.esri.ags.symbols::TextSymbol and there are no other TextSymbol classes defined. 

I put together a simple widget to test this behavior.  Adding any graphic other than a text graphic will turn one of the "Is" labels to true, while for text graphics all labels remain false.  Tell me if you get the same results.  Any help would be appriciated.

Note: This behavior only occurs when the graphic is accessed by another widget.  When accessing the widget from the Draw widget code itself, "textGraphic.symbol is TextSymbol" will evaluate true as expected.  But from another widget, its consistently false.

<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget 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:viewer="com.esri.viewer.*" 
       creationComplete="init()">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.events.GraphicEvent;
   import com.esri.ags.events.MapEvent;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.ags.symbols.FillSymbol;
   import com.esri.ags.symbols.LineSymbol;
   import com.esri.ags.symbols.MarkerSymbol;
   import com.esri.ags.symbols.Symbol;
   import com.esri.ags.symbols.TextSymbol;
   
   import mx.collections.ArrayCollection;
   import mx.events.FlexEvent;
   
   private function init():void
   {
    var graphicsLayer:GraphicsLayer = null;
    
    var layers:ArrayCollection = ArrayCollection(map.layers);
    for each(var layer:Layer in layers) {
     if(layer.name == "Draw Features") {
      graphicsLayer = GraphicsLayer(layer);
      addGraphicListener(graphicsLayer);
     }
    }
    
    map.addEventListener(MapEvent.LAYER_ADD, function(event:MapEvent):void {
     var layer:Layer = event.layer;
     if(layer.name == "Draw Features") {
      graphicsLayer = GraphicsLayer(layer);
      addGraphicListener(graphicsLayer);
     }
    });
   }
   
   protected function addGraphicListener(graphicsLayer:GraphicsLayer):void {
    graphicsLayer.addEventListener(GraphicEvent.GRAPHIC_ADD, function(event:GraphicEvent):void {
     var graphic:Graphic = event.graphic;
     var symbol:Symbol = graphic.symbol;
     typeLabel.text = describeType(symbol).@name;
     isMarkerSymbolLabel.text = (symbol is MarkerSymbol).toString();
     isLineSymbolLabel.text = (symbol is LineSymbol).toString();
     isFillSymbolLabel.text = (symbol is FillSymbol).toString();
     isTextSymbolLabel.text = (symbol is TextSymbol).toString();
    });
   }

  ]]>
 </fx:Script>
 <viewer:WidgetTemplate width="300" height="300">
  <mx:VBox>
   <mx:HBox>
    <s:Label text="Type:"/>
    <s:Label id="typeLabel" text=""/>
   </mx:HBox>
   <mx:HBox>
    <s:Label text="Is MarkerSymbol:"/>
    <s:Label id="isMarkerSymbolLabel" text=""/>
   </mx:HBox>
   <mx:HBox>
    <s:Label text="Is LineSymbol:"/>
    <s:Label id="isLineSymbolLabel" text=""/>
   </mx:HBox>
   <mx:HBox>
    <s:Label text="Is FillSymbol:"/>
    <s:Label id="isFillSymbolLabel" text=""/>
   </mx:HBox>
   <mx:HBox>
    <s:Label text="Is TextSymbol:"/>
    <s:Label id="isTextSymbolLabel" text=""/>
   </mx:HBox>
  </mx:VBox>
 </viewer:WidgetTemplate>
</viewer:BaseWidget>
Tags (2)
0 Kudos
2 Replies
DasaPaddock
Esri Regular Contributor
Can you try changing this line in WidgetManager.loadWidget() from:

wgtInfo.load(null, null, null, moduleFactory);

to:

wgtInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);

For background on this change, widgets are being loaded into separate sibling ApplicationDomains so they can't share class definitions. With the above change, they should be loaded into the main app's own domain.

Another work-around would be to make sure the TextSymbol definition is inherited from the parent domain by using it somewhere like creating an unused instance in index.mxml.

Reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.ht... (Also see last two See Also links.)
0 Kudos
JonathanNagy
New Contributor
That did the trick.  Thanks Dasa.
0 Kudos