Dec 15

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.

Here’s the fla.

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?