简体   繁体   English

AS3:访问外部加载的 swf 文件的函数时出错

[英]AS3: Error while accessing a function of an externally loaded swf file

I get the following error:我收到以下错误:

Error #1069: Property externalFun not found on LoadedFile and there is no default value.错误 #1069:在 LoadedFile 上找不到属性 externalFun,并且没有默认值。

My main project file:我的主要项目文件:

        questionLoader = new Loader();
        var questionRequest:URLRequest = new URLRequest(xmlName);
        questionLoader.load(questionRequest);
        questionLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);

 public function swfLoaded(e:Event) {

        var target: MovieClip = e.currentTarget.content;
        trace(target);

        addChild(target);
        target.externalFun();
    }

Loaded swf:加载瑞士法郎:

   public function LoadedFile() {
        // constructor code

        this.addEventListener(Event.ADDED_TO_STAGE,init);

    }

    public function externalFun():void {

    trace("IT WORKS");

    }

Any ideas?有任何想法吗?

Listen to Event.INIT rather than Event.COMPLETE .Event.INIT而不是Event.COMPLETE Event.COMPLETE happens immediately after all bytes are loaded and does not indicate that loaded content is actually available already. Event.COMPLETE在所有字节加载后立即发生,并不表示加载的内容实际上已经可用。 If you care to put one trace before calling externalFun and the other into the LoadedFile constructor, the latter one will fire later than the former.如果您想在调用externalFun之前将一个跟踪放入LoadedFile构造函数中,另一个跟踪将比前者更晚触发。 However, Event.INIT occurs after the loaded content is initialized thus the problem probably will go away.但是, Event.INIT发生在加载的内容初始化之后,因此问题可能会消失。 If no, proceed with trace diagnostics described above and probably wait 1 frame after Event.INIT fires before calling the function you want.如果不是,请继续进行上述跟踪诊断,并可能在Event.INIT触发后等待 1 帧,然后再调用所需的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM