Domain Lock in AS3, kind of

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?

6 Responses

  1. Andy Cook Says:

    Nice! Thanks a lot. I tweaked it a little bit to fit my needs but the structure is great!

  2. Yillb Says:

    Good stuff. Thanks.

  3. Sharon Says:

    Thank you for information! :)

  4. dave Says:

    how do you allow playing swf in local HD while restricting in one domain ?
    And how you redirect the thief to another website ?

    thanks

  5. uwe Says:

    thank you for this script.
    what about a local dns-server to fake the needed domain? Is this possible?

  6. Eddie Says:

    It’s good practice to remove event listeners. :] thanks

    else{ removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.