正在加载问题缩略图

发布于 2024-09-15 11:25:00 字数 1035 浏览 7 评论 0原文

我在加载缩略图时遇到问题,我为每个缩略图在舞台上加载设置了一个时间间隔。其中一些无法按顺序加载,它们丢失,滞后......

实际上,我将预加载器设置为文件大小,但由于我从 XML 动态加载,因此文件大小较小。

有谁知道解决该问题的解决方案? 不过,这确实让我很烦恼...

我加载了 XML 文件,并且解析过程没有任何问题。

有时,所有缩略图都可以加载到舞台上,如果带宽有点慢,则表示滞后意味着第一个缩略图正在加载,然后它突然跳过第二个缩略图,而是加载第三个缩略图,依此类推...

有时它可以加载整个缩略图...这很奇怪

,我在这里设置了一个计时器来加载每个缩略图

protected static const INTERVAL_TIME:uint       = 1000;
initLoadTime = new Timer(INTERVAL_TIME);
initLoadTime.addEventListener(TimerEvent.TIMER, handleLoadedEachThumbnail, false, 0, true);
initLoadTime.start();

protected function handleLoadedEachThumbnail(event:TimerEvent):void
{
var container:MovieClip = new MovieClip();

if (currentIndex < tabPhoto.length) {
 thumbnailPositionMC = positionEachThumbnail();
 container.addChild(thumbnailPositionMC);
 addChild(container);


 currentIndex++;
}

if (currentIndex == tabPhoto.length) {
 currentIndex = 0;
 initLoadTime.removeEventListener(TimerEvent.TIMER, handleLoadedEachThumbnail);
 initLoadTime.stop();
}

}

I'm having issue while loading thumbnail, I set an interval of time for each thumb to load on stage. Some of them can't load sequential in order, they are missing, are lagging...

Actually, I set a preloader to the file size but since I load dynamically from XML, file size is smaller.

Does anyone know a solution to solve that issue?
It's really bug me though...

I load with XML file and don't have any issue with parsing process.

Sometimes all thumbnails can be loaded on Stage, if bandwidth a bit slow it's lagged mean first thumb is loading then it's suddenly skip the second thumbnail, it loads third thumbnail instead and so on...

Sometimes it can load the whole thumbnails... it's weird

Here, I set a timer to load each thumbnail

protected static const INTERVAL_TIME:uint       = 1000;
initLoadTime = new Timer(INTERVAL_TIME);
initLoadTime.addEventListener(TimerEvent.TIMER, handleLoadedEachThumbnail, false, 0, true);
initLoadTime.start();

protected function handleLoadedEachThumbnail(event:TimerEvent):void
{
var container:MovieClip = new MovieClip();

if (currentIndex < tabPhoto.length) {
 thumbnailPositionMC = positionEachThumbnail();
 container.addChild(thumbnailPositionMC);
 addChild(container);


 currentIndex++;
}

if (currentIndex == tabPhoto.length) {
 currentIndex = 0;
 initLoadTime.removeEventListener(TimerEvent.TIMER, handleLoadedEachThumbnail);
 initLoadTime.stop();
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-09-22 11:25:00

我认为最好创建一个循环并使用加载器的 Event.COMPLETE 来知道何时加载下一个缩略图,而不是使用间隔。这样你就会避免冲突。

var imageLoader:Loader;
var currentImageLoading:uint;
var thumbsToLoad:Array; //array of strings of paths to the thumbnail

function loadThumbs(thumbs:Array):void
{
    currentImageLoading = 0;
    thumbsToLoad = thumbs;
    loadNextThumb();

function loadNextThumb():void
{
    imageLoader = new Loader();
    var imageUrl:String = thumbsToLoad[currentThumbLoading];
    var imageRequest:URLRequest = new URLRequest( imageUrl );
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadThumbComplete);
    imageLoader.load( imageRequest );
}

function loadThumbComplete(e:Event):void
{
    // do stuff with loaded thumb here
    var thumb:Sprite = new Sprite();
    thumb.addChild(imageLoader.content);
    trace(thumb.width);
    currentThumbLoading++;
    if (currentThumbLoading < thumbsToLoad.length) {
        loadNextThumb();
    } else {
        // loading cycle is complete
    }
}

评论后编辑

我修复了 loadThumbComplete 以获取事件参数。为了获取加载的拇指的宽度,我更喜欢从 imageLoader 中获取内容并将其放入 Sprite 中。

I think it would be better to create a loop and use the loader's Event.COMPLETE to know when to load the next thumbnail instead of using an interval. That way you will avoid conflicts.

var imageLoader:Loader;
var currentImageLoading:uint;
var thumbsToLoad:Array; //array of strings of paths to the thumbnail

function loadThumbs(thumbs:Array):void
{
    currentImageLoading = 0;
    thumbsToLoad = thumbs;
    loadNextThumb();

function loadNextThumb():void
{
    imageLoader = new Loader();
    var imageUrl:String = thumbsToLoad[currentThumbLoading];
    var imageRequest:URLRequest = new URLRequest( imageUrl );
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadThumbComplete);
    imageLoader.load( imageRequest );
}

function loadThumbComplete(e:Event):void
{
    // do stuff with loaded thumb here
    var thumb:Sprite = new Sprite();
    thumb.addChild(imageLoader.content);
    trace(thumb.width);
    currentThumbLoading++;
    if (currentThumbLoading < thumbsToLoad.length) {
        loadNextThumb();
    } else {
        // loading cycle is complete
    }
}

Edited after comments

I fixed the loadThumbComplete to take the event parameter. To get the width of the loaded thumb I prefer to take the content from the imageLoader and put it in a Sprite.

迷离° 2024-09-22 11:25:00

我已将 tabPhoto 和 tabThumbWidthIncrement 声明为 Vector

var tabPhoto:Vector.<ThumbInfo> = new Vector.<ThumbInfo>;
var tabThumbWidthIncrement:Vector<uint> = new Vector.<uint>;

I have declared tabPhoto and tabThumbWidthIncrement as Vector

var tabPhoto:Vector.<ThumbInfo> = new Vector.<ThumbInfo>;
var tabThumbWidthIncrement:Vector<uint> = new Vector.<uint>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文