When creating a flash game for the web it's crucial to know the domain the game SWF is being loaded from. There are numerous ways to embed a SWF in a website and the different methods of obtaining the domain name at run-time are giving different values. For example a game could be hosted in sourcedomain.com but displayed in a web page at another domain, say hotlinkingdomain.com. In this case there is one method to obtain the domain that is hosting the SWF and other methods of obtaining the domain that is embedding (hot linking) that SWF.
The proper way to determine the actual domain a SWF file is being hosted on is to use the Security.pageDomain property. It will give you the domain portion of the web address containing the SWF file. In other words the domain that is serving the SWF file.
import flash.system.Security;
var domain:String = Security.pageDomain;
var domain:String = Security.pageDomain;
API Reference: Security.pageDomain
There are numerous other ways to get domain information. A common way is to extract it from the LoaderInfo class. It's URL property (loaderInfo.url) however represents the web page the SWF is being loaded in (embedded, hot linked) and that's not necessarily the same address as the one the SWF resides physically.
The same result can be achieved by creating a LocalConnection object and inspecting it's "domain" property.
import flash.net.LocalConnection;
var localConnection:LocalConnection = new LocalConnection();
var domain:String = localConnection.domain;
var localConnection:LocalConnection = new LocalConnection();
var domain:String = localConnection.domain;
The above methods could be used in conjunction to check if the SWF is viewed and hosted on a certain website, so that it could behave accordingly. Especially if the SWF file is a popular flash game many websites will be embedding it directly from the source domain. In that case the game could be programmed in a way to compensate for the increased bandwidth - by displaying an advertisement for example, or disabling certain game features.
Site-locking a game to certain domain is something that needs to be achieved for a sponsored game. For my latest game Dungeon Screener I have utilized those methods in order to manage only one game file for all website instances out there. The game has a complex site-locking mechanism and it behaves differently if viewed at the sponsor website and at any other possible websites, except those restricting the SWF file with allowNetworking set to "never". In that case checking the HTML embedding restrictions in a SWF at runtime comes handy.
See how to determine AllowScriptAccess and AllowNetworking params with AS3.