2013-02-07 54 views
0

当我想要加载我的Flex项目在我的资产,我得到这个错误:的SecurityError:错误#2142:安全沙箱冲突

SecurityError: Error #2142: Security sandbox violation: local SWF files 
cannot use the LoaderContext.securityDomain property. 
app:/Main.swf was attempting to load app:/assets/stories/bear.swf. 

我创建一个LoaderContext并将其分配到的SWFLoader但我仍然得到这个错误。这里是我的代码:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:ns1="*" 
       applicationDPI="240" creationComplete="initApp(event)"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 
      import flash.system.SecurityDomain; 
      import flash.system.ApplicationDomain; 

      protected function initApp(event:FlexEvent):void 
      { 
       var context:LoaderContext = new LoaderContext(); 
       context.securityDomain = SecurityDomain.currentDomain; 
       context.applicationDomain = new ApplicationDomain(); 

       Story.loaderContext = context; 
       Story.source = "app:/assets/stories/Bear1.swf"; 
      } 

     ]]> 
    </fx:Script> 
    <s:SWFLoader id="Story" left="0" right="0" top="0" bottom="0" 
       trustContent="true" 
       scaleContent="true"/> 
</s:Application> 

我Flex中读了很多关于安全策略,但我还是没弄明白我怎样才能让我的应用程序的本地访问。

+0

这个问题没有妥善解决。但由技巧你摆脱这.. – Devendra

+0

@dev我可以使用@嵌入,但恐怕最后的SWF需要更长的时间来加载,特别是我的资产非常大。 – bman

+0

你试过swfloader? – Devendra

回答

0

在这种情况下,不需要使用loaderContext。由于这是一个移动项目,所有资产都被认为是本地的。我做错了的是将'assets'目录放在'src'目录之外。只有'src'目录内的目录才会导出到最终项目中。

0

您可能会通过使用thisthis获得解决方案。

+0

感谢您的链接。这些解决方案可能在Flash中工作,但它们实际上并不在Flex中工作。我不想加载跨域文件。我只想加载一个本地文件。提供LoaderContext或NOT提供相同的异常。 – bman

相关问题