Urkel asked at the Kongregate forums if anyone could help him with the domain lock in AS3. Well I donât know AS3, as for me itâs still âIâll dig into it tomorrowâ, but with help from Google and Flash Help Iâve modified the first example from Flash Rightsâ Domain Control page so that itâs⌠well, maybe not pure AS3 but compiles as if it were. Anyway maybe someone will use it or will rewrite it so that it fits standards and stuff. For now it works and thatâs a start.
Here’s a live swf. It doesn’t lock anything – it just shows domain.
Source:
import flash.events.*;
import flash.display.LoaderInfo;function enterFrameHandler(event:Event):void {
var url:String=stage.loaderInfo.url; //this is the magic _url successor
var urlStart:Number = url.indexOf(“://”)+3;
var urlEnd:Number = url.indexOf(“/”, urlStart);
var domain:String = url.substring(urlStart, urlEnd);
var LastDot:Number = domain.lastIndexOf(“.”)-1;
var domEnd:Number = domain.lastIndexOf(“.”, LastDot)+1;
domain = domain.substring(domEnd, domain.length);
txt.text=domain;if (domain != “mywebsite.com”) {
// do nasty things to thief
}
}addEventListener(Event.ENTER_FRAME, enterFrameHandler);
Sidenote: I need some good AS source formatting wp plugin and sth like lighbox with swf support. Anyone?
March 13th, 2008 at 7:00 pm
Nice! Thanks a lot. I tweaked it a little bit to fit my needs but the structure is great!
May 8th, 2008 at 7:51 pm
Good stuff. Thanks.
November 3rd, 2008 at 1:13 pm
Thank you for information!
November 6th, 2008 at 7:37 pm
how do you allow playing swf in local HD while restricting in one domain ?
And how you redirect the thief to another website ?
thanks
February 25th, 2009 at 10:55 am
thank you for this script.
what about a local dns-server to fake the needed domain? Is this possible?
May 14th, 2010 at 1:41 am
It’s good practice to remove event listeners. :] thanks
else{ removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}