4 Replies Latest reply on Jun 18, 2009 5:24 AM by dzeikei

    Get hostname

    greatshri

      Dear All,

      Thanks in advance.

       

      I want a script in flex which will fetch the host name form url.

      I have some scripts but it fetched the host name from the host the swf is hosted.

       

      Let me explain.

       

      I have my site on  www.mysite.com which embeds a flex swf.

      I have hosted it on another server say.. www.myotherserver.com/assets/flash/app.swf

       

      I want a script in flex which fetched the host name at runtime.

       

      Hope this make sense.

      Thanks.

        • 1. Re: Get hostname
          leybniz Level 4

            import mx.core.Application;
            import mx.utils.URLUtil;


            public static const DYNAMIC_MARKER:String = '[[DYNAMIC]]';

           

            public static function appContextUrl(includeFolder:Boolean = true):String {
             var url:String = Application.application.url;
             var protocol:String = URLUtil.getProtocol(url);
             var domain:String = URLUtil.getServerNameWithPort(url); 

             if (protocol == 'file')
              return 'http://localhost/';

             var folder:String = url.replace(protocol + '://' + domain, '');  
             folder = folder.slice(0, folder.lastIndexOf('/'));

             // Cut DYNAMIC_MARKER if App built using RSL's
             if (folder.indexOf(DYNAMIC_MARKER) >= 0) {
              folder = folder.slice(0, folder.lastIndexOf(DYNAMIC_MARKER) - 1);
              // cut swf module name
              folder = folder.slice(0, folder.lastIndexOf('/'));
             }

             if (!includeFolder)
              folder = '';

             return protocol + '://' + domain + folder + '/';  
            }

           

          If you feel this message answers your question or helps, please mark it respectively

          1 person found this helpful
          • 2. Re: Get hostname
            greatshri Level 1

            Thank You ,

             

            Alexander Mazuruk

             

            But your script give me the host name of the server where my swf files are loaded and not from the browser url.

             

            Thank you.

            • 3. Re: Get hostname
              leybniz Level 4

              BrowserManager.getInstance().url

              1 person found this helpful
              • 4. Re: Get hostname
                dzeikei Level 2

                I believe you are looking for

                 

                BrowserManager.getInstance().base