Easy way to handle development / production urls in flex air app
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
a source to share
I suggest either using a config file or modifying the hosts file to point domains to local or dev servers on your development machine. With the latter option, you always use your production URLs in code, but your development machine will resolve those domains on your local machine as it checks the hosts file first.
a source to share
The best approach here is to externalize this information in a config file - perhaps an XML file that is loaded via a relative URL. The config file might look like this:
<config>
<serviceEndpoint>http://www.mydomain.com/services</serviceEndpoint>
</config>
Be sure to name your XML elements with valid ActionScript variable names, or you may run into some difficulty working with the file (for example, E4X expressions can get difficult.
You can then use the HTTPService to load the "config.xml" that is placed alongside your SWF application during deployment. This will allow you to remap SWF hosted on any domain to a backend hosted elsewhere. This is especially useful if you are developing locally and connecting to a shared development server.
Compiling this information into your SWF is very inflexible and bad practice.
a source to share
I usually look at url
in an object contentLoaderInfo
in an 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 starts with "file" you know you are in development / IDE, if it is "http" it runs in the browser. If you are just working in a browser, you can also pass a parameter to an object that has something like
{
url: $_SERVER['SERVER_NAME'];
}
and execute some init / startup method to switch based on the path the application is running in.
a source to share
I had this problem in an AIR application I am writing that gets into a Rails application 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).
Here's 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 is a very easy way to switch between development / production environments.
a source to share