简体   繁体   English

AS3停止外部swf

[英]AS3 Stop external swf

Hi I'm loading an external swf into a MovieClip, and I want it to stop until I choose to play. 嗨,我正在将一个外部swf加载到MovieClip中,我希望它停止直到我选择播放。 Currently it plays upon loading immediately. 目前它在立即加载时播放。

var mc:MovieClip;

var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, eventLoaded); 
var request:URLRequest;
request = new URLRequest("external.swf");
swfLoader.load (request);

function        eventLoaded(e:Event): void
{
   mc = e.target.content as MovieClip;
// does not stop the clip
   mc.Stop ();
}

So I tried adding a Event.ENTER_FRAME to the movieclip and stop it there, that will stop but it will play the first frame. 所以我尝试将一个Event.ENTER_FRAME添加到movieclip并在那里停止,它将停止但它将播放第一帧。 Is there a way to get it to stay stopped when loaded until I choose Play? 有没有办法让它在加载时保持停止直到我选择播放?

It's actually very close to what Jochen Hilgers suggested. 它实际上与Jochen Hilgers建议的非常接近。 However, in this instance, the event you want is actually INIT instead of COMPLETE . 但是,在这种情况下,您想要的事件实际上是INIT而不是COMPLETE INIT is fired when the content is not yet fully loaded but is ready for use (and will start playing on its own). 当内容尚未完全加载但已准备好使用(并将自行开始播放)时会触发INIT

Attach the event with 附上活动

loader.contentLoaderInfo.addEventListener(Event.INIT, handleReady );

And handle it with 并处理它

public function handleReady( initEvent:Event ):void{
        MovieClip(initEvent.currentTarget.content).stop();
}

You'll notice that you can cast the content property of currentTarget as a MovieClip and stop it even before it has been attached to the stage. 您会注意到,您可以将currentTargetcontent属性currentTarget为MovieClip,并在将其附加到舞台之前将其停止。

It is important to note that it is not safe to use the content property in a PROGRESS event (or any time prior to an INIT or COMPLETE event). 请务必注意,在PROGRESS事件中(或INITCOMPLETE事件之前的任何时间)使用content属性是不安全的。 You will get an error to the effect that the object is not ready. 您将收到一个错误,指出对象尚未就绪。

I wrote this simple TestCase and it works fine... the loaded swf is quite simple, just a tween on the main timeline. 我写了这个简单的TestCase,它工作得很好......加载的swf非常简单,只是主时间轴上的补间。

package {
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;

    public class Test extends Sprite
    {
        private var loader:Loader = new Loader;

        public function Test()
        {
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaded );
            loader.load( new URLRequest( 'testFile.swf' ) );    
        }

        public function handleLoaded( event:Event ):void
        {
            addChild( loader.content );
            var mc:MovieClip = loader.content as MovieClip ;
            mc.stop();
        }
    }
}

I was looking for a similar problem/solution, but my problem was little diferent. 我一直在寻找类似的问题/解决方案,但我的问题差别不大。 I know this was not your issue, but looks fair to share my solution. 我知道这不是你的问题,但看起来很公平地分享我的解决方案。 When I tried to do 当我试着做的时候

    event.currentTarget.stop(); // AS1&AS2 -> BAD swf to import

with the content of a loader, my Flash IDE showed me this error: 使用加载程序的内容,我的Flash IDE向我显示了这个错误:

"Property stop not found on flash.display.AVM1Movie and there is no default value." “在flash.display.AVM1Movie上找不到属性停止,并且没有默认值。”

This happened to me because the swf I imported was created using AS1, and not AS3 as the main movie ( so I decompiled the swf to a fla and recompiled using as3, it was an output from After Effects). 这发生在我身上,因为我导入的swf是使用AS1而不是AS3作为主电影创建的(所以我将swf反编译为fla并使用as3重新编译,它是After Effects的输出)。 Now I know AVM1 and AVM2 are classes that represent actionscript 1 and 2 files. 现在我知道AVM1和AVM2是代表actionscript 1和2文件的类。

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

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