AS3 停止外部 swf [英] AS3 Stop external swf

查看:32
本文介绍了AS3 停止外部 swf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将外部 swf 加载到 MovieClip 中,我希望它在我选择播放之前停止.目前它在加载时立即播放.

Hi I'm loading an external swf into a MovieClip, and I want it to stop until I choose to play. 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 ();
}

所以我尝试向影片剪辑添加一个 Event.ENTER_FRAME 并将其停在那里,这会停止,但会播放第一帧.有没有办法让它在加载时保持停止状态,直到我选择播放?

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. Is there a way to get it to stay stopped when loaded until I choose Play?

推荐答案

它实际上与 Jochen Hilgers 的建议非常接近.但是,在这种情况下,您想要的事件实际上是 INIT 而不是 COMPLETE.INIT 在内容尚未完全加载但可以使用(并将开始自行播放)时触发.

It's actually very close to what Jochen Hilgers suggested. However, in this instance, the event you want is actually INIT instead of COMPLETE. INIT is fired when the content is not yet fully loaded but is ready for use (and will start playing on its own).

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

并处理它

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

您会注意到您可以将 currentTargetcontent 属性转换为 MovieClip 并在它附加到舞台之前停止它.

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.

请务必注意,在 PROGRESS 事件中(或在 INIT 之前的任何时间使用 content 属性是不安全的> 或 COMPLETE 事件).你会得到一个错误,表示对象没有准备好.

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). You will get an error to the effect that the object is not ready.

这篇关于AS3 停止外部 swf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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