2013-04-04 74 views
2

我试图通过我的Flash项目播放Youtube视频。视频播放,但我得到下面的错误,它毁了我的项目的其余部分。我找不到有这个确切错误的地方。我一直在试图理解它告诉我的是什么,但我无法将我的头围绕在它周围。 错误:安全沙盒违例闪存AS3

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

下面是我对球员的代码:

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; 
} 

这是我最后一年的大学项目的一部分,因此,如果任何人有任何想法,编号很乐意给它一个尝试。在此先感谢:)

+0

你有没有看这些问题:http://stackoverflow.com/q/9660286/78782,http://stackoverflow.com/q/5594647/ 78782,http://stackoverflow.com/q/4850465/78782,http://stackoverflow.com/q/2771787/78782,http://stackoverflow.com/q/11441645/78782 – 2013-04-04 04:18:45

回答

2

出于安全原因,FlashPlayer将本地和远程两个沙箱(网络)分开。您只能使用其中的一种,但无法同时加载内容。从本地文件系统加载的每个swf都在本地沙箱中考虑,其他所有内容都在网络沙箱中考虑。

所以现在你的swf是从文件系统加载的,而不是从web服务器加载的,并且flash会在本地沙箱中加以考虑,那么你的swf从远程/网络沙箱即www.youtube.com加载内容,就像我上面提到的那样,在本地沙箱中运行的swf无法从远程沙箱加载内容,而在远程沙箱中的swf无法加载本地沙箱中的内容。所以错误是很自然的。

allowDomain()只允许来自同一个沙箱不同的域即可以加载从www.youtube.com的内容为从www.yourdomain.com

形成更多的信息加载SWF有关安全沙箱中看到这一点:http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3f.html

现在来解决你的问题:

1)你可以从localhost设置本地HTTP服务器locf swf。

2)或者你可以把你的swf放在本地可信的swf列表中。只允许本地可信swf同时加载来自两个沙箱的内容。有关如何将swf放入本地受信任列表的信息,请参阅下面的链接。

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

2

尝试包括交domain.xml文件像您的项目如下图所示。

<?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> 

否则,请尝试在安全设置面板下添加您的内容。 http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

更多有关安全沙箱是指:http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3f.html