Security Sandbox Violation Flash AS3

2019-02-26 12:43发布

I'm trying to play a Youtube video through my flash project. The video plays but I get the error below and it ruins the rest of my project. I couldn't find anywhere that had this exact error. Ive been trying to understand what it's telling me but I just cant wrap my head around it. Error:

*** Security Sandbox Violation ***
SecurityDomain 'http://s.ytimg.com/yts/swfbin/apiplayer3-vflmoXxFm.swf' 
tried to access incompatible context 'file:flashProject.swf'

Here's the code I have for the player:

Security.allowDomain("www.youtube.com");

var my_player:Object;

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

function onLoaderInit(e:Event):void{
addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
} 

function onPlayerReady(e:Event):void{
my_player.setSize(600,300);
my_player.cueVideoById("76BboyrEl48",0);
my_player.x = stage.stageWidth/2 - my_player.width/2;
my_player.y = stage.stageHeight/2 - my_player.height/2;
} 

This is part of my Final Year college project so if anyone has any ideas Id be more than happy to give it a try. Thanks in advance :)

2条回答
神经病院院长
2楼-- · 2019-02-26 13:37

For security reasons FlashPlayer separates two sandboxes local and remote(network). At time you are only allowed to use one of them, you cannot load content from both same time. Every swf loaded from local file-system is considered in local sandbox, everything other is considered in network sandbox.

So now your swf is loaded from file-system not from web-server and flash considers it in local sandbox, then your swf loads content from remote/network sandbox i.e. from www.youtube.com, as I mentioned above, swf running in local sandbox cannot load content from remote sandbox and same for swf in remote sandbox cannot load content from local sandbox. So error is natural.

allowDomain() only allows different domains from same sandbox i.e. you can load content from www.youtube.com to into swf loaded from www.yourdomain.com

Form more info about security sandboxes see this: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3f.html

Now to fix your problem:

1) You can setup local HTTP server locad swf from localhost.

2) Or you can put your swf in local trusted swf list. Only local trusted swf are allowed to load content from both sandboxes at same time. See link below for info how to put your swf in local trusted list.

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3f.html

查看更多
三岁会撩人
3楼-- · 2019-02-26 13:45

try including a cross-domain.xml file like the one shown below on your project.

<?xml version="1.0"?>
<cross-domain-policy>
   <site-control permitted-cross-domain-policies="all"/>
   <allow-access-from domain="*"/>
   <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

Otherwise try adding your content here under the security settings panel. http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

for more about security sandbox refer: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3f.html

查看更多
登录 后发表回答