views:

136

answers:

5

Easy way to handle developemnt/production URLs in flex air app? I want to point to my local box for testing, but when I launch I want it to automatically point to the production URL.

A: 

I suggest either using a configuration file or changing your hosts file to point domains to localhost or dev servers on your development machine. With the latter option you always use your production URLs in code, but your dev machine will resolve those domains to your local machine because it checks the hosts file first.

apphacker
A: 

You can use namespaces and configure the current namespace (DEV/RELEASE) in your compiler options.

CONFIG::release
public function connect()
{
  //connect to release url
}

CONFIG::dev
public function connect()
{
   //connect to dev url
}

then define these options for the compiler:

-define=CONFIG::release,false
-define=CONFIG::dev,true
Joel Hooks
So much hate for a perfectly viable solution!
Joel Hooks
A: 

The best approach here is to externalize this information into a config file - perhaps an XML file - that is loaded via a relative url. The config file might like look this:

<config>
    <serviceEndpoint>http://www.mydomain.com/services&lt;/serviceEndpoint&gt;
</config>

Be sure to name your XML elements with valid ActionScript variable names or you may encounter some difficulty working with the file (for instance, E4X expressions may become difficult.

You can then use HTTPService to load "config.xml" which is placed alongside your application's SWF when deployed. This will allow you to repoint a SWF hosted on any domain to backend hosted anywhere else. This is especially useful if you are developing locally and are connecting to a shared development server.

Compiling this information into your SWF is very inflexible and a poor practice.

cliff.meyers
A: 

I typically will look at the url in the contentLoaderInfo object in either the Application (Flex -- http://livedocs.adobe.com/flex/201/langref/mx/core/Application.html#url) or root display object (Flash -- http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html#url). If the url begins with "file", you know you are in your development/IDE, if it's "http", it's being run in a browser. If you're just working in the browser, you might also pass a parameter to the object that has something like

{
    url: $_SERVER['SERVER_NAME'];
}

and perform some init/startup method to switch based on the path the app is running under.

Typeoneerror
A: 

I had this very issue in an AIR app I am writing that hits a Rails app via WebORB.

I just need to switch between http://localhost and http://fakeproductionurl.com depending on whether I was running in Flex Builder (via adl).

This is what I ended up using:

if (NativeApplication.nativeApplication.publisherID != "") {
   return "http://fakeproductionurl.com";
}
else {
   return "http://localhost";
}

It doesn't give you the ability to switch between 3+ different environments, but it's a very easy way to toggle between development / production environments.

Doug Hays