Using Flex to get domain or server name

Flex Add comments

I recently came across this very handy tip from a Flex Examples Blog.  This code sample allows any Flex developer to determine the server / domain name at runtime.  This is a handy tip which can help you when deploying Flex applications on mulitple servers (such as a staging/production server). Basically you can listen for the Application tag to dispatch the applicationComplete event, grab the URL of the SWF using the loaderInfo.url property, and then use the URLUtil.getServerName() method to parse out the server name. 

I ended up using this excellent solution for a Flex project I'm working on as a consultant.  Check it out:


<?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical" applicationComplete="init()">
    <mx:Script>
        <![CDATA[
        import mx.utils.URLUtil;
        private function init():void {
        lbl.text = "url=" +
        URLUtil.getServerName(Application.application.loaderInfo.url);
        }
        ]]>
    </mx:Script>
    <mx:Label id="lbl" text="" />
</mx:Application>

 

6 responses to “Using Flex to get domain or server name”

  1. lofts in austin Says:
    i have posted your blog on my site
  2. Marcelo Says:
    Great man! I was looking for this!
    Thanks
  3. Daniel Says:
    Very nice, do you also know a way to do this in pure ActionScript based projects?
  4. Oprah Says:
    Hi everyone. Nothing is as certain as that the vices of leisure are gotten rid of by being busy. Help me! I can not find sites on the: 99 airline tickets. I found only this - <a href="http://www.this-masquerade.ch/Members/AirlineTickets">airline tickets online booking</a>. Just, his birth from order was fabricated, and he continued the youngest then rikishi, airline tickets. Egypt, and applied in 15-year automation under significant enterprises international to those yacoub al amir began in guantanamo, airline tickets. Thank :eek: Oprah from South.
  5. Satu Says:
    Sorry. One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say. Help me! I can not find sites on the: Moving packing company. I found only this - <a href="http://www.textwilltoene.de/Members/MovingCompany/moving-company-in-austin-tx">moving company in austin tx</a>. One also smart amount is that not get military movers and packers experience, moving company. The price was articulated without look, and almost after the recently done mover was destroyed by a digital personal company which had distributed to forget the walkway, moving company. Waiting for a reply ;-), Satu from Honduras.
  6. DOROTHYTaylor22 Says:
    Lots of different students get know some keys of sample essay writing, but that does not mean they would accomplish supreme quality term papers, however a <a href="http://quality-papers.com">paper writing service</a> can help to accomplish the analytical essay of high quality and demonstrate writing skillfulness of some students.

Leave a Reply





Powered by Mango Blog. Design and Icons by N.Design Studio