Flash AS3:电影开始播放时加载栏未完成
我使用的代码与我总是用于预加载另一个 swf 的代码相同,但这次不起作用。这次的问题是,当加载条达到 16% 时,每次您都可以听到我正在加载的电影在后台播放。我可以在正在加载的电影的第一帧(“Trial_1.swf”)中添加一个停止点,但是如何告诉它在加载后转到第二帧?
非常感谢任何帮助!
这是我的代码:
var myrequest:URLRequest = new URLRequest("trial_1.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
myloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progresshandler);
function progresshandler (myevent:ProgressEvent):void {
var myprogress:Number = myevent.target.bytesLoaded / myevent.target.bytesTotal;
bar_mc.scaleX = myprogress * 1.5;
myTextField_txt.text = Math.round(myprogress * 100) + "%"
}
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, finished);
function finished (myevent:Event):void {
addChild(myloader);
removeChild(myTextField_txt)
removeChild(bar_mc);
removeChild(logo_mc);
}
I'm using the same code I always use for preloading another swf but it's not working this time. The problem this time is that when the loading bar gets to 16% every time you can hear the movie I'm loading playing in the background. I can just add a stop to the first frame of the movie I'm loading ("trial_1.swf") but how do I tell it to go to the second frame once it has loaded?
Any help is much appreciated!
Here's my code:
var myrequest:URLRequest = new URLRequest("trial_1.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
myloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progresshandler);
function progresshandler (myevent:ProgressEvent):void {
var myprogress:Number = myevent.target.bytesLoaded / myevent.target.bytesTotal;
bar_mc.scaleX = myprogress * 1.5;
myTextField_txt.text = Math.round(myprogress * 100) + "%"
}
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, finished);
function finished (myevent:Event):void {
addChild(myloader);
removeChild(myTextField_txt)
removeChild(bar_mc);
removeChild(logo_mc);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在 Trial_1.swf 的开头放置一个特殊的起始帧(以及第一帧上的
stop();
),其中按钮保持“开始电影”。单击该按钮时,它会使用gotoAndPlay(2);
将时间线移动到第 2 帧。如果您这样做,则由用户决定何时开始播放动画,并且只有在完全加载且 swf 位于舞台上后才能完成。那应该可以解决你的问题。
但说实话,我不确定为什么你的动画在完全加载之前就开始播放。这确实很奇怪。
Why not put a special starting frame at the beginning of your trial_1.swf (along with the
stop();
you've got on that first frame) which has as button staying 'Start Movie'. When the button is clicked, it moves the timeline to frame 2 withgotoAndPlay(2);
.If you do it like that it's up to the user when to start playing the animation, and it can only be done once it's loaded fully, and the swf is on the stage. That should solve your problem.
To be honest though, I'm not sure why your animation is beginning to play before it's fully loaded. That's certainly odd.