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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With