Search code examples
asp.netapache-flexactionscriptpathurl-mapping

Getting ASP.NET root path to Flex?


I am working on a project that is primarily ASP.NET based. The main project is meant to be deployed to multiple locations for different clients, so one client might be located at website.com/client1 and another at website.com/client2. Within the application, we regularly use the application root operator ~ to get the path to a resource.

We also have a bunch of Flex applications that get deployed in there, and many rely on web services within the ASP.NET application. What I'm after is a way to reference the services relative to the application root. Here's an example of the location of some files for two client deployments:

  • Client A
    • website.com/clientA/swf/FlexApplication.swf
    • website.com/clientA/services/webService.asmx
  • Client B
    • website.com/clientB/swf/FlexApplication.swf
    • website.com/clientB/services/webService.asmx

FlexApplication and webService are both exactly the same, so what I want to do is something like this in the Flex code:

var myService:CustomService = new CustomService(~/services/webService.asmx);
myService.callMethod("Test");

I would like to avoid using relative paths for the usual reasons. Is there a good way to do this or a good way to pass the root url to the flex application from ASP.NET? Thanks in advance.


Solution

  • Its definitely a good idea to avoid relative URL's. The easiest way is to pass the information in via Flash Vars in the HTML embed statement.

    Check out Adobe's documentation on using FlashVars with Flex: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html

    Summary:

    Add a line to the HTML embed statement like this:

    <param name='flashVars' value='serviceRoot=/myserviceRoot'/>
    

    Then access it in Flex via the mx.core.Application.application.parameters accessor

    import mx.core.Application;
    
    var parameters:Object = Application.application.parameters;
    var serviceRoot:String = parameters['serviceRoot'];