Flash - 将影片剪辑添加到加载器中
我已经为我的 swf 文件创建了一个预加载器。我想在加载另一个 swf 时简单地将图像添加到舞台上。
我的图像保存在库中名为 image 的影片剪辑中。我如何将它添加到舞台上并使其在加载时保持在那里。我尝试过手动将其移动到舞台上,但它只停留一帧。
import flash.display.*;
import flash.events.*;
import flash.text.*;
var myContent:URLRequest = new URLRequest("flashheader.swf");
var myLoader:Loader = new Loader();
myLoader.load(myContent);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoader);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function preLoader(event:ProgressEvent):void
{
var loaded:Number = Math.round(event.bytesLoaded);
var total:Number = Math.round(event.bytesTotal);
var percent:Number = loaded/total*100;
percentText.text = Math.round(percent) + "%"
}
function loadComplete(event:Event):void
{
addChild(myLoader);
removeChild(percentText);
谢谢
,
DIM3NSION
i have created a preloader for my swf file. I want to simply add an image onto the stage whilst another swf is loading.
My image is saved in a movieclip called image in the library. How would i add it to the stage and make it stay there whilst it is being loaded. I have tried manually moving it onto the stage but it only stays for 1 frame.
import flash.display.*;
import flash.events.*;
import flash.text.*;
var myContent:URLRequest = new URLRequest("flashheader.swf");
var myLoader:Loader = new Loader();
myLoader.load(myContent);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoader);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function preLoader(event:ProgressEvent):void
{
var loaded:Number = Math.round(event.bytesLoaded);
var total:Number = Math.round(event.bytesTotal);
var percent:Number = loaded/total*100;
percentText.text = Math.round(percent) + "%"
}
function loadComplete(event:Event):void
{
addChild(myLoader);
removeChild(percentText);
}
Thanks,
DIM3NSION
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只保留一帧的原因可能是因为舞台(您的主时间轴)上有几个帧,所以它只是一闪而过。
尝试添加 stop();如果这是时间轴上第一帧上的动作脚本,则位于此代码的顶部。
无论如何,您需要放置一个 stop() 以防止阶段自动前进到时间线的下一帧。
看看这是否可以为您解决问题,或者请要求澄清。
编辑:好的,你说它时不时地闪烁,所以你的影片剪辑中100%确定有不止一帧。特别是如果您添加了 stop()。确保所有影片剪辑都具有精确的 1 帧,而不仅仅是舞台,如果这是您拥有的整个代码并且您看到它闪烁(该图像的影片剪辑必须循环或其他),则必须如此。
The reason it stays only for one frame is probably because the stage (your main timeline) has several frames on it, so it just zips by.
Try adding a stop(); at the top of this code if this is actionscript on the first frame on the timeline.
In any case, you need to place a stop() to prevent the stage from automatically progressing to the next frame of the timeline.
See whether this fixes it for you or ask for clarifications please.
Edit: OK, you said it's flashing every now and again, so you have more then 1 frame in one in your movieclips 100% sure. Especially if you added the stop(). Make sure all movieclips have exatcly 1 frame, not just the stage, it has to be that if this is the whole code you have and you see it flashing (the movieclip for that image has to be looping or something).