//In BaseWidget.as add private static var _Widget:BaseWidget; //Then in the initWidgetTemplate function add _Widget = this;
Naty,
So you are missing more code that was discussed in the original tread then.//In BaseWidget.as add private static var _Widget:BaseWidget; //Then in the initWidgetTemplate function add _Widget = this;
The QueryPID error means that you need to look in your SearchWidget for a public function called QueryPID. In the original thread I called it "public function queryPPIN(sParam:String):void".
The CustomDraw error means that your MapManager code is now looking for my EnhancedDraw widget instead of the standard draw tool of ESRI's. That code was not in Sandra's MapManger code so If you are not using my custom draw widget than I would say look back up at the beginning of this thread and grab Sandra's MapManager code she posted.
//Add to your SearchWiget.mxml
//query parameter
public function querybmpid(sParam:String):void
{
var i:Number = cboLayerText.selectedIndex;
queryLayer = configSearchText.url;
if(queryExpr){
}else{
queryExpr = configSearchText.expr;
}
queryFields = configSearchText.fields;
queryTitleField = configSearchText.titlefield;
queryLinkField = configSearchText.linkfield;
if (queryLayer)
{
var queryTask:QueryTask = new QueryTask(queryLayer);
var query:Query = new Query();
var pExpr:String = sParam.toUpperCase();
var expr:String = queryExpr.replace("[value]", pExpr);
query.where = expr;
query.outFields = queryFields.split(",");
query.returnGeometry = true;
query.outSpatialReference = map.spatialReference;
queryTask.execute(query, new AsyncResponder(onResult, onFault));
showMessage(loadingLabel, true);
showStateResults(null);
// on result
function onResult(featureSet:FeatureSet, token:Object = null):void
{
try
{
var recAC:ArrayCollection = createRecordData(featureSet);
addSharedData(widgetTitle, recAC);
wRepeater.dataProvider = recAC;
showMessage(selectionLabel + " " + featureSet.features.length, false);
onLoadDone(null);
map.cursorManager.removeAllCursors();
}
catch (error:Error)
{
showMessage(error.message, false);
onLoadDone(null);
}
}
//on fault
function onFault(info:Object, token:Object = null) : void
{
onLoadDone(null);
showMessage(info.toString(), false);
}
}
}Naty,
I am not sure what you have the function in your SearchWidget called...
Try adding this function to your SearchWidget.mxml if you don't have it.//Add to your SearchWiget.mxml //query parameter public function querybmpid(sParam:String):void { var i:Number = cboLayerText.selectedIndex; queryLayer = configSearchText.url; if(queryExpr){ }else{ queryExpr = configSearchText.expr; } queryFields = configSearchText.fields; queryTitleField = configSearchText.titlefield; queryLinkField = configSearchText.linkfield; if (queryLayer) { var queryTask:QueryTask = new QueryTask(queryLayer); var query:Query = new Query(); var pExpr:String = sParam.toUpperCase(); var expr:String = queryExpr.replace("[value]", pExpr); query.where = expr; query.outFields = queryFields.split(","); query.returnGeometry = true; query.outSpatialReference = map.spatialReference; queryTask.execute(query, new AsyncResponder(onResult, onFault)); showMessage(loadingLabel, true); showStateResults(null); // on result function onResult(featureSet:FeatureSet, token:Object = null):void { try { var recAC:ArrayCollection = createRecordData(featureSet); addSharedData(widgetTitle, recAC); wRepeater.dataProvider = recAC; showMessage(selectionLabel + " " + featureSet.features.length, false); onLoadDone(null); map.cursorManager.removeAllCursors(); } catch (error:Error) { showMessage(error.message, false); onLoadDone(null); } } //on fault function onFault(info:Object, token:Object = null) : void { onLoadDone(null); showMessage(info.toString(), false); } } }
If you call it querybmpid like above it should match the MapManger.mxml of Sandra's that I told you to switch to.
This is definitely not an easy piece of code to implement as there are many vital steps to the code that need to be in place and it helps if you try to understand the path that the code is taking.
Basically the application loads and check is there is a URL Parameter for the search and if there is once the map is loaded then programatically launch the SearchWidget and pass that parameter to it and run the query. So the MapManager needs to check for the paramter, find the search widget and launch it and then when you have the reference to the searchwidget call the (what ever function i.e. queryPPIN) and execute the search. So the MapManager has to call a valid function in the SearchWidget.
Thank U so much Robert, I compiled and I built all my project....but nothing happen... 😞
I know it's really hard to understand why it doesnt work...but if u have time please help me ... in attachment I send u my MapManager, SiteContainer and SearchWidget.
Many thanks.
Naty
function timerComplete( event:TimerEvent ):void
{
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
var id:Number = SiteContainer.getInstance().getWidgetId("My Widget Label");
var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
if (bWidget){
var bWidg:BaseWidget = bWidget.getInstance();
var vSW:myWidget= bWidg as myWidget;
vSW.myQueryFunction(id);
} else {
var bWidget2:IBaseWidget;
bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
var vSW2:BuscarDerechoMinero = bWidget2 as BuscarDerechoMinero;
vSW2.buscarDerecho(id_Derecho);
}
}
var id:Number = SiteContainer.getInstance().getWidgetId("My Widget Label");
is the name of your search widget as it is defined in your config.xml?...
function timerComplete( event:TimerEvent ):void
{
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
var id:Number = SiteContainer.getInstance().getWidgetId("Búsqueda DM");
var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
if (bWidget){
var bWidg:BaseWidget = bWidget.getInstance();
var vSW:BuscarDerechoMinero = bWidg as BuscarDerechoMinero;
vSW.buscarDerecho(id_Derecho);
} else {
var bWidget2:IBaseWidget;
bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
var vSW2:BuscarDerechoMinero = bWidget2 as BuscarDerechoMinero;
vSW2.buscarDerecho(id_Derecho);
}
}
<widget label="Búsqueda DM" icon="com/esri/solutions/flexviewer/assets/images/icons/i_derecho.png" menu="menuWidgets" config="com/esri/solutions/flexviewer/xml/BuscarDerechoMinero.xml">com/esri/solutions/flexviewer/widgets/BuscarDerechoMinero.swf</widget>
var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; ... bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
public function getWidget(id:Number):IBaseWidget
{
var widget:IBaseWidget;
var label:String = configData.configWidgets[id].label;
var icon:String = configData.configWidgets[id].icon;
var config:String = configData.configWidgets[id].config;
var url:String = configData.configWidgets[id].url;
var preload:String = configData.configWidgets[id].preload;
if (widgetTable.containsKey(id))
{
widget = widgetTable.find(id) as IBaseWidget;
widget.setState("maximized");
var wObj:DisplayObject = widget as DisplayObject;
scrollToWidget(wObj);
}
else
{
//module loaded
if (moduleTable.containsKey(url))
{
var modInfo:IModuleInfo = moduleTable.find(url) as IModuleInfo;
widget = modInfo.factory.create() as IBaseWidget;
widget.setId(id);
widget.setTitle(label);
widget.setIcon(icon);
widget.setConfig(config);
widget.setConfigData(configData);
widget.setMap(map);
var widgetDO:DisplayObject = widget as DisplayObject;
widgetBox.addChild(widgetDO);
widgetTable.add(id, widget);
}
else
{
return null;
loadWidget(id, url,preload);
}
}
return widget;
}