PDA

View Full Version : Loading thumbnails



ahmednuaman
May 12th, 2008, 12:13 PM
I'm trying to load some thumbnails on the fly but some of them aren't loading up. It's not random, it's always the same ones that don't load. My code works like this:

init() -> gets a JSON response with an array containing a load of thumbnails. A variable is then set and kept global.

loadThumbs() -> creates a moviecip, adds a drawn rectangle as a sprite to it, and then adds a loader to that sprite. That loader is passed a URL to the thumbnail. The loader gets the right URL and the loader's http status is 200 (which is 'ok', literally). After that, once the loader has finished, the thumbnails slide into position.

However, it's always the same thumbnails that don't load. So here's some code to mull over:


function loadThumbs (e):void {
workContainer.removeEventListener(Event.ADDED,load Thumbs);
workContainer.x = (stage.stageWidth / 2) - (workContainerProps.bigwidth / 2); trace(workContainer.x);

thumbsProps.countX = thumbsProps.countY = 0;

for (var i:Number = 0; i < workProps.thumbs.length; i++) {
this['thumbcontainer'+i] = new MovieClip();
this['thumb'+i] = new Sprite();
this['loader'+i] = new Loader();
this['url'+i] = new URLRequest(urlProps.url + '/' + workProps.thumbs[i]); trace(urlProps.url + '/' + workProps.thumbs[i]);

this['thumb'+i].graphics.beginFill(0xFFFFFF,1);
this['thumb'+i].graphics.drawRect(0,0,thumbsProps.width,thumbsPro ps.height);
this['thumb'+i].graphics.endFill();

this['thumb'+i].name = i;
this['thumb'+i].buttonMode = true;

this['thumb'+i].addChild(this['loader'+i]);
this['loader'+i].contentLoaderInfo.addEventListener(Event.COMPLETE ,resizeThumbs);
this['loader'+i].load(this['url'+i]);

this['thumb'+i].addEventListener(MouseEvent.CLICK,loadNextWork);

this['thumbcontainer'+i].alpha = 0;

this['thumbcontainer'+i].addChild(this['thumb'+i]);

workContainer.addChild(this['thumbcontainer'+i]);

TweenMax.to(this['thumbcontainer'+i],timeProps.fast / 24,
{ ease: Strong.easeOut,
y: (Math.random() * workContainerProps.height) - (this['thumbcontainer'+i].height / 2),
x: (Math.random() * workContainerProps.width) - (this['thumbcontainer'+i].width / 2),
autoAlpha: 1/*, onComplete: loadThumbnail, onCompleteParams: [ this['thumb'+i] ]*/ });

}

}

function resizeThumbs (e):void {
var loader = e.target.loader;
var sprite = loader.parent;
var mc = sprite.parent;
//var newBg:Sprite = new Sprite();
this['newbg'+bgI] = new Sprite();

this['newbg'+bgI].graphics.lineStyle(thumbsProps.border,0xFFFFFF,1) ;
this['newbg'+bgI].graphics.beginFill(0xFFFFFF,1);
this['newbg'+bgI].graphics.drawRect(0,0,e.target.width,e.target.hei ght);
this['newbg'+bgI].graphics.endFill();

mc.addChildAt(this['newbg'+bgI],0);

TweenMax.to(mc,timeProps.medium / 24,{ ease: Strong.easeOut, x: calculateThumbPosX(), y: calculateThumbPosY(), overwrite: false });

bgI++;

}



Many thanks for any help!

ahmednuaman
May 12th, 2008, 01:00 PM
Fix:

I added a new movieclip, added that to workContainer, and then added the thumbnails to the new movieclip. Simple.