tags:

views:

3884

answers:

5

Hey,

I'm working on a project for school right now and we're trying to get it set up so that it is easily deployable. The webapp portion of it is written entirely in Adobe flex.

However, we need links to certain files / url's within the code which are different on different machines.

For instance, my server might use 8180 as the port while someone else uses 8080. Or one person is using Windows so a filepath would be C:/... while mine would be /home/...

Is there any way we could put these files into a separate config file and read them dynamically within the mxml files?

It would be really nice if we didn't have to recompile for each individual deployment...

Thanks in advance!

A: 

If you have enabled the local-file sandbox, you may be able to use URLLoader to read a local file:

http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=05B_Security_176_04.html

However, your SWF must also be local.

If you are loading the SWF remotely, you can connect back to the loading server for a list of resources. That should probably be the preferred solution in most cases.

Mitch Haile
A: 

You can pass in parameters into a SWF by adding FlashVars to the HTML that it's running from. FLashVars

CookieOfFortune
Great idea, I forgot about flashvars.
Mitch Haile
+1  A: 

You can use HTTPService to load an XML file (or any text file) that is in a location relative to the Flex application SWF. Simply execute the HTTPService on application startup, parse the file, and make the data available wherever you need it.

cliff.meyers
A: 

I strongly agree with brd6644. You will need a cross domain policy file on the server where the config files reside. Just copy the following XML to a file named "crossdomain.xml" and put it on the server root of the server that contains your config files.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy 
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt;
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>

You may not need this if the swf resides on the same server as the config files. Also, as you can see, this cross domain policy allows access from all domains, so if you care a lot about security (may not be important for a school project), read up a bit on them to see how to configure. Here is a good article

Also, here is some sample HTTPService code:

private function init():void{
     get_bands_service.url = yeswewillArtistsURL;
     get_bands_service.method = "GET";
     get_bands_service.addEventListener(FaultEvent.FAULT, onServiceFault);
     get_bands_service.requestTimeout = 20;
     get_bands_service.send();
}

<mx:HTTPService id="get_bands_service" result="parseBandsServiceResult();" useProxy="false" />
Tony
A: 

Check out appcorelib, the docs will show you how to use a relative URL like from an assets folder:

loadXML("assets/xml/config.xml);

Don't need to worry about crossdomain if the xml and flex app are on same server.

Brandon