I’ve been fond of experimenting on things and so this time with what I do and work on most. I’ll try to make some research and test based on what I have made. These posts won’t be recognized as 100% accurate and correct on all situations although I aim to be at the most. See disclaimer before implementing any theories and/or statements described in. So let me start with an quite old issue with disabling external links upon embedding an swf in a web page.
Since flash player 9, site owners were allowed to take use of the additional security. You can control a SWF file’s access to network functionality by setting the allowNetworking parameter in the <object> and <embed> tags in the HTML page that contains the SWF content. It can be included by having:
<object width="100" height="100" data="sample.swf" type="application/x-shockwave-flash"> <param name="id" value="sampleswf" /> <param name="allowNetworking" value="internal" /> <param name="src" value="sample.swf" /> <param name="name" value="sampleswf" /> </object>
See your help file about this or view the livedocs (as2 or as3) discussing this added security. Basically if this ever happens to a flash game, the developer and/or sponsor are neglected of having click backs to their own sites/portals, which is not a good thing. So I made a little research and test if actionscript can determine if allowNetworking was enabled or not. This test will try to determine if external links are allowed, not exactly return the value of the allowNetworking parameter. I made a sample page here having 2 swfs (as2 & as3) embedded in different ways: using the basic embed-object tags, AC_RunActiveContent.js and swfobject class. As said in that page, the swfs on the left uses allowNetworking set to “internal” so it should say “External links disabled” and the swfs on the right doesn’t so it should say “External links ok”. Then try clicking on the links on each swf and determine if the message displayed respectively complies (either disabled or OK), if so then it pass if not then a fail. And these are the results I had (all with winXP):
| basic Embed | AC_RunActiveContent.js | swfobject class | ||||
| AS2 | AS3 | AS2 | AS3 | AS2 | AS3 | |
| Firefox 3.03 | pass | pass | pass | pass | pass | pass |
| Opera 9.5 | pass | pass | pass | pass | pass | pass |
| Safari 3.1.2 | pass | pass | pass | pass | pass | pass |
| Chrome 0.2.149.30 | pass | pass | pass | pass | pass | pass |
| IE 7.0.5730 | fail | pass | pass | pass | pass | pass |
| IE 6 | fail | pass | pass | pass | pass | pass |
| IE 5.5 | fail | pass | pass | pass | pass | pass |
In conclusion: I wasn’t successful with AS2, and to mention that the AS2 code that I used is just a trick and not legally proven in anyway. Also if you try to make a trap-like-function with your game/project/swf you should also be aware that opening external links are disabled with standalone flash players by default (which I think implements allowNetworking = “internal” with the standalone player’s sandbox). So the when the AS3 sample is ran using the standalone player you can catch the error number which will be error #0. Note: If you are using another browser which I haven’t tested or another OS, you are very much encouraged to comment out if my sample page worked properly or not with what you have.
So how did I made those results? Here are the codes that I used:
Please read the DISCLAIMER first before you do anything with what you’ll see and learn.
Actionscript 2:
import flash.external.ExternalInterface; var allowNetworking; var str:String; try{ allowNetworking = ExternalInterface.call(null); str = allowNetworking +''; if ( str == 'null' ) { throw new Error("Error"); }else{ _root.test.htmlText = 'external links OKn"'+ str +'"'; } }catch( $e ){ _root.test.htmlText = 'external links DISABLEDn "'+ str +'"'; } btn.onRelease = function(){ getURL("http://jaycsantos.com","_blank"); }
In AS2, if the ExternalInterface.call() failed it doesn’t throw an error unlike in AS3 so I have to make some workarounds with AS2 to get a return value from any possible function call and ExternalInterface.call() is my only chance. ExternalInterface.call(null) was expected to return a null value when allowNetworking is set to either “internal” or “none” and was supposed to be undefined when not. It was almost a passing code trick but IE has failed once again making the whole AS2 test a failure.
Actionscript 3:
import flash.external.ExternalInterface; var allowNetworking:Object; try{ allowNetworking = ExternalInterface.call(null); test.htmlText = 'external links OK'; }catch( $e:* ){ test.htmlText = 'external links DISABLEDn err #'+ $e.errorID +''; } function mouseClickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://jaycsantos.com/")); } btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
Practically I used ExternalInterface.call(null) instead of trying to instantiate URLRequest because if it succeeds it would open up an external link and might just be blocked by a popup-blocker since the code is ran without user interaction. Unlike AS2, it will simply throw in an error when the network method is restricted.
Please read the DISCLAIMER first before you do anything with what you’ve seen and learned.
I would not recommend using any of this in a professional project or until further tests are made. But it somehow shows logic that it should work especially with the AS3 code, so use at your own risk.


•
Share your thoughts, socialize!