SecurityError:错误#2142:安全沙箱冲突

时间:2013-02-07 05:14:23

标签: flex

当我想在我的Flex项目中加载我的资产时,我收到了这个错误:

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中阅读了很多关于安全策略的内容,但我仍然没有弄清楚如何允许本地访问我的应用程序。

2 个答案:

答案 0 :(得分:0)

您可以使用thisthis获得解决方案。

答案 1 :(得分:0)

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