Talking about Flash.
Sometimes you need to make your Flash movie (or game) to work only on selected domains. Sometimes you may want to blacklist some domains so they can’t display your Flash content.
This is called sitelocking, and means you lock a movie to a specific site.
Let’s see how can you sitelock a Flash file.
The first thing we need to know is where the movie is been played.
With the _url
property we can determine the absolute path of a movie clip.
I will create a movie with a text field instanced as domain
with this actionscript:
domain.text = _url;
This is the result:
Next we have to determine the domain name, so we need some string functions. First we need to strip all characters before ://
(://
included).
Using the split
method, I’ll split a the domain name into substrings by breaking it wherever ://
is found, in this way:
domain_parts = _url.split("://");
domain.text = domain_parts[1];
Splitting the domain name by :// will create an array with its first element (at index 0) containing http
(or https
, or whatever I’ll find before the ://
), and the second element with the remaining part of the domain. Look:
We are few steps away from having only the domain name.
In the same way as before, now I have to split the string when I find a /
domain_parts = _url.split("://");
real_domain = domain_parts[1].split("/");
domain.text = real_domain[0];
Here it is:
Now, we are ready to sitelock the game. Just remember that some portals do not use their domain to host Flash games. For example, NewGrounds uses uploads.undergrounded.net
while Kongregate uses chat.kongregate.com
.
Anyway, the customer who will request to sitelock your Flash movie will tell you which domain you have to lock the game on.
Now, let’s think about what to do when the movie is played in a site you don’t want to be played. The easiest thing is making the root transparent so it will impossible for the surfer to use it.
sitelock("emanueleferonato.com");
function sitelock(url_to_lock) {
domain_parts = _url.split("://");
real_domain = domain_parts[1].split("/");
domain.text = real_domain[0];
if (real_domain[0] != url_to_lock) {
_root._alpha = 0;
}
}
This function will display the game only if played on my domain.
Now, the last interesting thing… how to sitelock to more than one site.
urls_allowed = ["emanueleferonato.com", "www.triqui.com"];
sitelock(urls_allowed);
function sitelock(urls_allowed) {
lock = true;
domain_parts = _url.split("://");
real_domain = domain_parts[1].split("/");
domain.text = real_domain[0];
for (x in urls_allowed) {
if (urls_allowed[x] == real_domain[0]) {
lock = false;
}
}
if (lock) {
_root._alpha = 0;
}
}
This one only allows movie to be played on this domain and on triqui.com
Hope you will find it useful
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.