Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript 3: How to get host name from URL?

I am trying to set a path to an XML file, which differs when run locally or on server.

How do I determine if the Flash is running locally? (I am thinking to check if the URL contains "http://localhost" but how do you get the window URL?)

Thanks in advance

like image 823
Aximili Avatar asked Dec 10 '22 21:12

Aximili


2 Answers

You can ask the external window (container) for this information through the external API

if (flash.external.available) // An external window is not always available
{
    var win:* = flash.external.call("window.location"); // evaluate window.location
    // depending on browser there are several properties like 'host' you can use
    // to get the actual hostname
    // e.g. win.host == "localhost"
}

If the above method doesn't work you need to create a wrapper function for returning that window.location object from JavaScript. Note that what properties that are available on the win Object is entirely set by the browser and varies between browsers. This also means that the flash player (which you get if you run the movie hosted by the flash player outside of a browser environment will not know about the window.location property, this works when you deploy your movie but not when debugging)

Check here for more information

  • http://developer.mozilla.org/en/DOM/window
  • http://www.google.se/search?hl=en&q=flash.external.ExternalInterface
like image 84
John Leidegren Avatar answered Feb 26 '23 06:02

John Leidegren


If your application is a Flex application, you can retrieve the URL of the main SWF file via the url attribute of your application object. This can be accessed from anywhere within your controller tree via parentApplication.url, or, if an object is not part of the controller tree, Application.application.url.

For plain AS3 projects, you need to access the loaderInfo attribute of your main sprite, e.g., _root.loaderInfo.url will give you the same information.

like image 38
David Hanak Avatar answered Feb 26 '23 08:02

David Hanak