加载SWF和使用它通过接口 [英] Loading swf and using it through interface

查看:151
本文介绍了加载SWF和使用它通过接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建简单的SWF与接口:

I've created simple swf with interface:

public class Test extends MovieClip implements ITest
{

    public function Test()
    {
        Security.allowDomain("*");
        Security.allowInsecureDomain("*");
    }

    public function speak(str):String
    {
        trace(str);
        return "yeah";
    }
}

ITEST:

ITest:

public interface ITest {

    // Interface methods:
    function speak(str):String
}

然后我试图加载它:

And then I'm trying to load it:

    public function SWFLoader() 
    {
        var url='http://xxxxxxxx/test.swf';
        var loadURL:URLRequest=new URLRequest(url);
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
        var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
        loader.load(loadURL, context);
    }

    private function completeHandler(event:Event):void 
    { 
        var test:ITest;
        test = event.target.content as ITest;
        test.speak("ggg");
    } 

所以,如果我有test.swf在同一目录下(本地方法),它的工作的罚款。但是如果我把它放在专用服务器上:(event.target.content为ITEST)返回null。不过,我可以访问说话()不带网络接口这样的event.target.content.speak(一!);

So if I have test.swf in the same directory(local way) it work's fine. But if I'm placing it on the dedicated server: (event.target.content as ITest) returns null. However, I can access speak() without interface like this event.target.content.speak("a!");

如何解决这个问题呢?

推荐答案

你如何你的两个SWF之间共享ITest接口?

How do you share the ITest interface between your two swf ?

我想你有两个项目,一个用于test.swf(加载一个),一个用于加载程序(我会打电话给他loader.swf)。我想你不能只是声明ITest接口的两倍(一个用于test.swf,一个用于loader.swf)。如果这样做,将有两个接口,使用相同的接口名称,同样的声明的方法,但他们仍然将是2个不同的接口。而铸造相互转换将失败。
我敢打赌,如果你这样做(所建议的帕特里克)

I imagine you have two projects one for the test.swf (the loaded one) and one for the loader (I'll call him loader.swf). I think you can't just declare the ITest interface twice (one for test.swf, one for loader.swf). If you do so, there will be two interfaces, with the same interface name, the same declared methods, but they still will be 2 different interfaces. And casting one into another will fail.
I bet that if you do (as suggested by PatrickS)

var test:ITest = ITest(event.target.content ); 

您会看到一个错误类型 - >这是这种形式铸造的优势。这证实了我认为:这两个接口是不同的。

You will see a type error -> that's the advantage of this form of casting. This will confirm what I think : the two interfaces are different.

要真正分享你的2个项目之间的接口,你应该将其存储到库(文件名为.swc),并使用该库在你的2个项目。这应该解决的问题。

To really share the interface between your 2 projects, you should store it into a library (.swc file) and use that library in your 2 projects. This should solve the issue.

这篇关于加载SWF和使用它通过接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆