加载的SWF将无法在空中执行其功能

问题描述 投票:0回答:2

回来寻求帮助!所以我正在创建一个AIR应用程序,将SWF加载到容器中以供用户查看。但是,当我将文件加载到其容器中时,加载的SWF无法执行自己的代码。 IE按下加载的SWF上的隐形按钮,它会改变颜色。我试过谷歌解决方案,因为Security.allowDomain(“*”);在flash中抛出此错误。但是根据我的阅读,AIR不允许加载的swfs执行代码以达到某些安全性原因,但我也不是100%肯定。

SecurityError: Error #3207: Application-sandbox content cannot access this feature.
at flash.system::Security$/allowDomain()
at BugFree()[D:\Desktop\BugFree\BugFree.as:72]

如果没有Allow域,则在尝试单击隐藏按钮时会抛出此安全错误。

*** Security Sandbox Violation ***
SecurityDomain 'file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf' 
tried to access incompatible context 'app:/BugFree.swf'
*** Security Sandbox Violation ***
SecurityDomain 'file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf' 
tried to access incompatible context 'app:/BugFree.swf'
SecurityError: Error #2047: Security sandbox violation: parent: 
file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf cannot access 
app:/BugFree.swf.
at flash.display::DisplayObject/get parent()
at TechDemoSwordNew_fla::Button_Play_21/onButtonPress()

这仅显示在Animate输出栏中。当我发布它时,使用运行时嵌入的应用程序,并打开exe它不会抛出任何错误,但隐形按钮仍然无法正常工作。

这是加载swf的代码。

btnButton.addEventListener(MouseEvent.CLICK, onButtonPress, false, 0, true);
function onButtonPress(event:MouseEvent):void
{
MovieClip(parent).play();
}
stop();

这是按钮内的时间线代码,因为这是将我的项目放入游戏中的游戏公司所做的事情。我最初提交它都是在课堂上完成的,但除此之外。按下按钮时,加载的SWF应播放然后停止。但是我得到了上面提到的Sandbox违规。

用于加载SWF的代码如下

public function WeaponLoad()
    {
        if(FileMenu.WeaponFileTxt.text != "")
        {
            LoadWeapon(FileMenu.WeaponFile.nativePath);
        }
        else if(FileMenu.WeaponFileTxt.text == "")
        {
            Character.mcChar.weapon.removeChildAt(0);
            Character.mcChar.weaponOff.removeChildAt(0);
        }
    }

public function LoadWeapon(strFilePath: String)
    {
        WeaponLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, CompleteWeaponLoad);
        WeaponLoader.load(new URLRequest(strFilePath), new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain)));
    }

public function CompleteWeaponLoad(e: Event)
    {
        var WeaponClass: Class;
        if (MiscMenu.WeaponSelect.MainClick.currentFrame != 3)
        {
            try
            {
                trace("WeaponOff");
                WeaponClass = WeaponLoader.contentLoaderInfo.applicationDomain.getDefinition(FileMenu.WeaponLinkTxt.text) as Class;
                this.Character.mcChar.weapon.removeChildAt(0);
                this.Character.mcChar.weaponOff.removeChildAt(0);
                this.Character.mcChar.weapon.addChild(new(WeaponClass)());
            }
            catch (err: Error)
            {
                trace("Either the weapon class doesnt exist or it is wrong");
                this.Character.mcChar.weapon.removeChildAt(0);
                this.Character.mcChar.weaponOff.removeChildAt(0);
            }
        }
        else if (MiscMenu.WeaponSelect.MainClick.currentFrame == 3)
        {
            try
            {
                WeaponClass = WeaponLoader.contentLoaderInfo.applicationDomain.getDefinition(FileMenu.WeaponLinkTxt.text) as Class;
                this.Character.mcChar.weapon.removeChildAt(0);
                this.Character.mcChar.weaponOff.removeChildAt(0);
                this.Character.mcChar.weapon.addChild(new(WeaponClass)());
                this.Character.mcChar.weaponOff.addChild(new(WeaponClass)());
            }
            catch (err: Error)
            {
                trace("Either the weapon class doesnt exist or it is wrong");
                this.Character.mcChar.weapon.removeChildAt(0);
                this.Character.mcChar.weaponOff.removeChildAt(0);
            }
        }
    }

由于我不知道如何在发布设置中更改任何安全沙箱设置,因为它对我来说是灰色的,因此任何帮助都会被贬低。就像我说的那样,我尝试使用Google搜索,但我似乎无法提出任何答案。另外值得注意的是我是一个自学成才的新手,我不知道很多关于AS3的事情。我知道我的代码可以更干净,我计划清理它并在基本程序启动并运行后正确减少内存消耗。感谢您的帮助!

security actionscript-3 air
2个回答
0
投票

您似乎没有正确设置应用程序域。以下是as3文档中包含的代码:

 var loader:Loader = new Loader();
 var url:URLRequest = new URLRequest("[file path].swf");
 var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
 loader.load(url, loaderContext);

在LoadWeapon功能中使用它。

在此期间,尽量不要使用大写字母来启动变量和方法名称。在ActionScript中,以大写字母开头的名称表示类名。它将广泛提高代码的可读性。


0
投票

你不能将swfs捆绑到AIR应用程序并使用File类加载它们吗?如果你想使用swfs中的类,可以考虑制作swc库吗?

© www.soinside.com 2019 - 2024. All rights reserved.