简体   繁体   English

当我在外部瑞士法郎上使用事件ADDED_TO_STAGE时,其执行次数是as3的两次

[英]Event ADDED_TO_STAGE executed two times as3 when I am using it on external swf

I got problem when I am loading external swf which contains added_to_stage method. 我在加载包含add_to_stage方法的外部swf时遇到问题。 It execute two times. 它执行两次。 I don t understand why it is doing ? 我不明白为什么会这样? I am also interesting if both swfs have their own stage ? 如果两个瑞士法郎都有自己的舞台,我也很有趣。

Thank you for any answer 谢谢你的回答

I am using greensock library to hanle loading. 我正在使用greensock库处理加载。

Flash preloader: Flash预载器:

package  {
    import flash.display.MovieClip;
    import com.greensock.loading.SWFLoader;

    public class Preloader extends MovieClip 
    {

        public function Preloader() 
        {
            var loader : SWFLoader = new SWFLoader("Prototype1.swf");
            loader.load();
            addChild(loader.content);
        }
    }
}

External SWF: 外部SWF:

public class Prototype1 extends MySprite 
{

    public function Prototype1() 
    {   
        addEventListener(Event.ADDED_TO_STAGE, onAdded);    
    }

    private function onAdded(e:Event):void
    {
        trace("onAdded");
    }
}

OUTPUT: onAdded onAdded 输出:onAdded onAdded

The greensock documentation says: greensock文档说:

suppressInitReparentEvents: Boolean - If true, the SWFLoader will suppress the REMOVED_FROM_STAGE and ADDED_TO_STAGE events that are normally dispatched when the subloaded swf is reparented into the ContentDisplay (this always happens in Flash when any DisplayObject that's in the display list gets reparented - SWFLoader just circumvents it by default initially to avoid common problems that could arise if the child swf is coded a certain way). preventInitReparentEvents suppressInitReparentEvents: Boolean -如果为true,则SWFLoader将抑制通常在将子加载的swf重新显示到ContentDisplay时分派的REMOVED_FROM_STAGE和ADDED_TO_STAGE事件(当显示列表中的任何DisplayObject被重新显示时,此事件通常在Flash中发生-SWFLoader只是绕过它默认情况下,默认情况下是为了避免以子方式对子swf进行编码时可能出现的常见问题)。

So you can change your code in Preloader.as to: 因此,您可以将Preloader.as中的代码更改为:

var loader:SWFLoader = new SWFLoader("Prototype1.swf", {suppressInitReparentEvents: true});

And you'll only get one call to onAdded . 而且,您只会接到onAdded一个电话。

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

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