Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在主类中具有设计接口的强制加载SWF_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 在主类中具有设计接口的强制加载SWF

Actionscript 3 在主类中具有设计接口的强制加载SWF,actionscript-3,flash,Actionscript 3,Flash,首先,我阅读了链接主题,但不幸的是,其中的任何提示都不适用于我: 我的问题确实是类似的,我创建了SWF Content.SWF where Content.as这是文档类: package { import flash.display.MovieClip; public class Content extends MovieClip implements IGame { public function igameMethod():void { trace("im

首先,我阅读了链接主题,但不幸的是,其中的任何提示都不适用于我:

我的问题确实是类似的,我创建了SWF Content.SWF where Content.as这是文档类:

package {   
import flash.display.MovieClip;

public class Content extends MovieClip implements IGame {

    public function igameMethod():void {
        trace("implemented method of IGame");
    }
}
}

与Content.as位于同一目录中的IGame接口包含唯一的方法“igameMethod”

package  {
public interface IGame {
    function igameMethod():void;
}
}

这种编译后的SWF是由LoadSWF中的Loader类加载的,其中Main.as是document类,类似于:

public class Main extends MovieClip {
    private var swfLdr:Loader;
    private var game:IGame;

    public function Main():void {
        if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        swfLdr = new Loader();
        var r:URLRequest = new URLRequest("../lib/Content.swf");
        var defaultLoaderContext:LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain);
        //none of settings for ApplicationDomain doesnt' work (with checkPolicy or with or without ApplicationDomain.currentDomain set)
        swfLdr.load(r,defaultLoaderContext);
        this.addChild(swfLdr);
        swfLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, onExternalSWFLoaded);
        //tried Event.INIT too without success
    }

    private function onExternalSWFLoaded(e:Event) : void {
        var Game:Class = ApplicationDomain.currentDomain.getDefinition( "IGame" ) as Class;
        if (e.target.content is IGame) {
            trace("Is IGame");
        }else {
            //output of this condition is false 
            //so e.target.content is not IGame
            trace("No its not IGame");
        }
        var Game:Class = ApplicationDomain.currentDomain.getDefinition( "IGame" ) as Class; 
        //tried to cast as class without success too
        var gameContent: IGame = IGame(swfLdr.content); //app breaks here
       // TypeError: Error #1034: Type Coercion failed: cannot convert LoaderSWF@87f0089 to IGame
    }
我还将IGame interace复制到LoadSWF项目中,其包结构与document class相同,位于与Main相同的文件夹中。至于让LoadSWF在Content.swf上使用igameMethod,但我无法使用它,因为TypeError:错误1034:类型强制失败:无法转换LoaderSWF@87f0089给我。因此编译器无法将此内容转换为IGame

你有什么想法,对我这个话题有帮助吗? 谢谢你提前给我提示。
最亲切的问候Pawel

您是否尝试过区分您的本地IGame和进口IGame?试着把它放在一个包中,并用特定的包路径进行寻址,例如:MyInterfaces.igame是的,我现在已经尝试过了,但没有成功。仍然是1034。使用DescripteTypeSWFLDR.content检查它会给我提供输出xml中的其他值:您确实用loaderSWF包装了swf,请将其展开。@BotMaster您能详细说明您的想法吗?我不太明白你的意思。在“发布设置”中,选择“合并到代码中”,否则将使用默认的预加载程序进行设置,该预加载程序会包装swf,并且不会实现界面。顺便说一句,接口必须导入到主项目中,并且不能被getDefinitionByName引用。