PDA

View Full Version : How can I site Lock a Flash


Platypus2008
05-10-2008, 11:49 AM
So that is can only be played on one website?

amarghosh
05-12-2008, 05:19 AM
i don't know if there is a direct method for this. but this is what i can think of:

u can write an external javascript method that returns the current html page (document.location) and call that from ur movie using ExternalInterface.call and check the value against a hardcoded string;
//script.js
function getSiteAddress()
{
return document.location;
}
//in the constructor of document class of ur AS file:
var page:String = ExternalInterface.call("getSiteAddress");
if(page != "www.platypus2008.com") // or whatever it is
displayErrorMessageAndStopPlaying();
don't embed script in html as anyone can view it in its source

how to hack it:
Download the javascript file from ur site (by typing www.platypus2008.com/script.js on his address bar);
edit it to return "www.platypus2008.com" (instead of document.location)
thats it: he would be able to run it from any site he wants to;

so u might wanna give some crazy names to js file; or somehow block it; all the best :)

APL_Designs
11-11-2008, 11:05 PM
Can anyone verify that this works in IE? It does not for me. The only thing I want to do is return the browser URL to a variable in Flash.

I can get FF to work perfectly, but IE is 'null' for each of the 20 ways I've tried already. I'm a new developer, and slowly building my skills, so any help would be appreciated. Of particular interest would be anyone who understands WHY IE returns 'null' and what the trick is to avoid this problem.

Thanks in advance.

sonicdoomx
11-12-2008, 02:27 AM
//Assuming you have a movieclip or sprite named myMovieClip (you can use any movieclip or sprite)
var URLofSWF:String = myMovieClip.loaderInfo.loaderURL;

//You will do some string methods to get domain name etc etc, it's up to you
var domain_parts:Array = _url.split("://");
var domain_parts_2:Array = domain_parts[1].split("/");
var domainOfURL:String = real_domain[0];

//Then you compare the URL to any URL you wish to allow or disallow
if(URLofSWF == "http://www.google.com/mySwf.swf"){ // strict swf url checking
proceed();
}else{
stopEverything(); // Or inject some funny code to the stealer :P
}
// or
if(domainOfURL == "www.mysite.com"){ // domain checking only
proceed();
}else{
stopEverything(); // Or inject some funny code to the stealer :P
}


Edit: I forgot to mention that you can google for this. But I saved you the trouble.

watcher
11-12-2008, 07:49 AM
heh just yesterday i bookmarked one site-lock idea (scroll to bottom):
https://www.mochiads.com/community/forum/topic/protect-as3-file

@sonicdoomx: seems pretty similiar to yours actually (oops)

APL_Designs
11-12-2008, 08:36 PM
Watcher and SonicDoomX,

I appreciate both of your replies, but I don't think this is what I need.

I am actually looking for the url address of the browser page. The url that I want to import into flash is from a cgi-driven page... and I want to extract part of that url, not necessarily where the swf file resides.

Most of the examples I see on other posts use the ExternalInterface.call(" return document.location") or some variation of that.

Many of the examples work perfectly in FF but none in IE. I may be missing something simple for IE compatibility in general?? I may be overlooking the obvious, so I'll continue to check my work.

Thanks.

raydowe
11-12-2008, 09:08 PM
The problem could be the way you're embedding your swf. Maybe it's not getting the variables passed in correctly.

If you aren't already I would recommend using swfobject http://code.google.com/p/swfobject/

Rossman
11-12-2008, 09:24 PM
sonicdoomx: This solution will only work if they have copied the SWF over to their webserver. If I have an HTML page and embed the SWF right off his domain the loaderInfo will return a "valid" URL. :-/

A better way is using ExternalInterface as previously suggested, like:


var SiteURL:String = String( ExternalInterface.call('function(){ return document.location; }') );

if (SiteURL == "http://www.mysite.com/")
{
trace( "Yay!" );
}
else
{
trace( "There be pirates ahoy!" );
}


Something like that, anyways.

wvxvw
11-12-2008, 09:30 PM
Actually it doesn't give you 100% protection, the stealer can use i-frames for example... And as long as you cannot protect SWF from downloading (meaning, you want to prevent hotlinking), then I'd think of outputing SWFs with PHP, where PHP would check where the request originates from. This isn't a 100% bulletproof protection, but will make it considerably more difficult.

Rossman
11-12-2008, 09:39 PM
Well, I mean, the only way to get bulletproof protection is to use the SWF protection features built in to Flash Media Server 3.

That aside, the ExternalInterface approach is valid and can be easily tweaked to detect and bust out of iframes, just as sites can currently do using Javascript today.

Of course, people could decompile the SWF and change the ExternalInterface call or whatever but the goal is to stop lazy and stupid folk, so you often don't have to do a lot to discourage them ;)

APL_Designs
11-12-2008, 11:47 PM
Rossman,

There is something simple wrong with my approach.

When I use the code you provided below, and simply try to set a dynamic text box to the url by:

browserurl.text = SiteURL;

I get null as usual in IE, and I get [object Object] in FF.

I'm certain this is an amateur mistake, but still, some guidance would be appreciated.
Thanks.

Rossman
11-13-2008, 12:03 AM
Sorry, you should change "document.location" to "document.location.href" ;)

APL_Designs
11-13-2008, 12:50 AM
Again, works perfect in FF, but null in IE...

Rossman
11-13-2008, 12:54 AM
This works good for me in IE and FF:


import flash.external.ExternalInterface;

var SiteURL:String = String( ExternalInterface.call('function(){ var afk = document.location.href; return afk; }') );

ExternalInterface.call('alert',SiteURL);

APL_Designs
11-14-2008, 01:39 AM
FYI for other new, uneducated developers, my primary problem turned out to be:

No id set for my flash object (on the HTML page).

As soon as I gave my flash object an id in dreamweaver it worked just like I wanted.

Thanks.