<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: error casting one widget into another in ArcGIS Viewer for Flex Questions</title>
    <link>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763096#M22860</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Valentina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; I would love to know the solution to this as well... I do have a workaround though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just don't declare the variable type of the widget you are after.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId(widgetLabel); //correct var
bWidget2:IBaseWidget; bWidget2 = ViewerContainer.getInstance().widgetManager.getWidget(id,false);//returns
LayerListParcelsWidget var vLLW2:* = bWidget2;
//Call some var or public function on the widget
//of course you will not have code completion for it though.
vLLW2.someVarriable or public function
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 08:25:50 GMT</pubDate>
    <dc:creator>RobertScheitlin__GISP</dc:creator>
    <dc:date>2021-12-12T08:25:50Z</dc:date>
    <item>
      <title>error casting one widget into another</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763095#M22859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's the scenario:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have created 3 new widgets, all identical copies of the LayerListWidget component, except for the widget label. At some point I want to execute a public function on those 3 widgets; its definition remains the same.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even after following Robert Scheitlin's advice from &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=158&amp;amp;f=2421&amp;amp;t=297813" rel="nofollow noopener noreferrer" target="_blank"&gt;this old thread&lt;/A&gt;&lt;SPAN&gt; and forcing the same application domain on all widgets (&lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/11960-com.esri.ags.symbols.TextSymbol-is-not-TextSymbol-in-FlexViewer-widget" rel="nofollow noopener noreferrer" target="_blank"&gt; ESRI recommendation&lt;/A&gt;&lt;SPAN&gt;), I am still unable to cast an instance of the new widget to the generic LayerListWidget (the original LayerListWidget is loaded as a module.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId(widgetLabel); //correct
var bWidget2:IBaseWidget;
bWidget2 = ViewerContainer.getInstance().widgetManager.getWidget(id,false);//returns LayerListParcelsWidget
var vLLW2:LayerListWidget = bWidget2 as LayerListWidget;//returns null&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The application domain is defined in WidgetManager.mxml as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;wgtInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Compiler arguments:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;-locale en_US -source-path=locale/{locale} -keep-all-type-selectors=true&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FlexViewer 2.4 (July 2011), Flex 4.1, ArcMap 10.0, SP1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like casting is not possible between identical component copies. Is there another way to do the casting?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Valentina Boycheva&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:25:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763095#M22859</guid>
      <dc:creator>ValentinaBoycheva</dc:creator>
      <dc:date>2021-12-12T08:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: error casting one widget into another</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763096#M22860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Valentina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; I would love to know the solution to this as well... I do have a workaround though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just don't declare the variable type of the widget you are after.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId(widgetLabel); //correct var
bWidget2:IBaseWidget; bWidget2 = ViewerContainer.getInstance().widgetManager.getWidget(id,false);//returns
LayerListParcelsWidget var vLLW2:* = bWidget2;
//Call some var or public function on the widget
//of course you will not have code completion for it though.
vLLW2.someVarriable or public function
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:25:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763096#M22860</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2021-12-12T08:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: error casting one widget into another</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763097#M22861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, Robert! The type annotation (star type) helped, indeed. The code wrapping feature had jumbled a bit your snippet. I am including it again for anyone interested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId(widgetLabel); //correct 
var bWidget2:IBaseWidget; 
bWidget2 = ViewerContainer.getInstance().widgetManager.getWidget(id,false);//returns LayerListParcelsWidget 
var vLLW2:* = bWidget2;
//Call some var or public function on the widget
//of course you will not have code completion for it though.
vLLW2.someVarriable or public function
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;There is another wrinkle, though: unless LayerListParcelsWidget is preloaded as open or at least minimized, bWidget2 will always be null. Which, of course, is not at all what I want. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the meanwhile, I realized that my solution architecture can be optimized. So, instead of 3 widgets, I have one widget with a ViewStack. This worked just fine and I avoided widget communication. One thing to remember with ViewStacks: to have all views loaded at completion time, include &amp;lt;creationPolicy="all"&amp;gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As for the original question - I wonder whether the casting will be possible between inherited components; that is if the new widget is not an exact copy but rather an extension of the original. No time to test now - just a note to myself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Valentina Boycheva&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-flex-questions/error-casting-one-widget-into-another/m-p/763097#M22861</guid>
      <dc:creator>ValentinaBoycheva</dc:creator>
      <dc:date>2021-12-12T08:25:53Z</dc:date>
    </item>
  </channel>
</rss>

