2013-02-07 91 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

相關問題