|Foumart Games Blog|
|2015-02-28||Get the domain a SWF is hosted in||Collapse|
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.
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.
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.
|2014-07-03||Check HTML restrictions in SWF. Determine AllowScriptAccess and AllowNetworking with AS3|
As I was digging around the allowNetworking setting and how to determine if it's allowed inside flash at runtime, I decided to go deeper and catch other types of embedding restrictions, like the allowScriptAccess parameter. I've seen sites that block outgoing links of certain flash files - in most cases flash games are prevented to access the web, resulting in negative effect over their authors - the game developers...
|2013-05-24||Atrakt 4096 successful entry in Ludum Dare #26 Compo|
Atrakt 4096 is minimalist mixture between Sci-Fi action and a sliding puzzle. Vanquish all alien spawns in this level based game, involving not only exploring and fighting but planning, stealth, strategy and logical thinking as well! This game was developed in Flash-AS3 and is an extension of my Attract 4kb engine which consists of 4 kilobytes of code (4 classes)...
|2013-04-10||DisplaceR - Displacement Map Filter Tweener - AS3|
DisplaceR is a lightweight Displacement Map Filter Tweener targeting Flash Player 9. Written in ActionScript 3.0¹², DisplaceR is built with the idea to be as simple as possible, becoming accessible by all kind of flash developers and designers. Being a static class makes it available anywhere in your project. Tweening is achieved only with one line of code...
|2012-10-23||Attract 4kb a 4096 bytes adventure !|
Born in 4kb Games on FlashGameLicense competition. A game that is exactly 4096 bytes :) It's featuring Artificial Intelligence, Fog of War, Player Health, 4 Maps and 12 Levels ! Developed in ActionScript 3 for Flash Player 9. Here is a Github link where you can view the optimized code...
© 2009-2017 by Noncho Savov
|FoumartGames.com is a computer game workshop and arcade website, led by independent game developer. The site showcases games and game prototypes invented and developed by Noncho Savov. Have fun!|