This is how I've set up one of my applications. I have one code base that runs several different projects, with each project using the same URL but with a separate parameter at the end. http://maps.coastalscience.noaa.gov/biomapper/biomapper.html?id=BUIShttp://maps.coastalscience.noaa.gov/biomapper/biomapper.html?id=StJohnThe app uses the parameter to get the information from the XML configuration file to add the different map layers needed for the project (as well as the text in all the information dialogs). Through this configuration file, I can change from our development to production server merely by changing the service node in the XML file without recompiling the swf.I read the configuration file in my init function like thisprivate function init():void
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE,init_onComplete);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,test);
xmlLoader.load(new URLRequest("parameters.xml")); //this is the configuration file
and start using it like this
private function init_onComplete(event:Event):void
{
var params:Object;
var baseImagery:String;
var layerBaseImagery:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer;
try
{
var loader:URLLoader = URLLoader(event.target);
xmlParameters = new XML(loader.data);
params = getURLParameters();
if (params["id"])
{
input = params.id
}
else
{
Alert.show("Parameter search failed");
return;
}
xmlProjectParameters = xmlParameters.project.(@urlinput==input);
var bm:IBrowserManager = BrowserManager.getInstance();
bm.init("", xmlProjectParameters.@id + " BIOMapper");
///etc.
}
private function getURLParameters():Object
{
var result:URLVariables = new URLVariables();
try
{
if (ExternalInterface.available)
{
var search:String = ExternalInterface.call("location.search.substring", 1);
if (search && search.length > 0)
{
result.decode(search);
}
}
}
catch (error:Error)
{
Alert.show(error.toString());
}
return result;
}
Through configuration file, I load dynamic or tiled layers
baseImagery = xmlProjectParameters.baseimagery;
layerBaseImagery.url = serverName + baseImagery + "/MapServer";
mainMap.addLayer(layerBaseImagery);
This is what the configuration file looks like
<?xml version="1.0" encoding="utf-8"?>
<projects>
<project id="Buck Island" urlinput="BUIS">
<projectname name="Buck Island, USVI" pdftitle="Buck Island, USVI: Shallow-Depth Benthic Habitats" url="http://ccma.nos.noaa.gov/ecosystems/coralreef/stcroix.aspx" projectyear="2011"/>
<service>http://egisws02.nos.noaa.gov/ArcGIS/rest/services/biomapper/BUIS_</service>
<baseimagery>Imagery</baseimagery>