Copy link to clipboard
Copied
This is how I'm loading my external images atm. The only problem is that I need to load all of them before they get placed on the stage. Even though my images take only 10-15kb, there's a considerable downtime at just 15 images. Would it be possible to place all instances of movieclip 'imgContainer' first, and then add images to them, or start placing imgContainer one by one as soos as consecutive images are getting loaded? I'd be grateful for any help.
public function Parseimage(imageinput: XML): void {
imageurl = imageinput.image.iurl;
listId = imageinput.image.id;
captions = imageinput.image.captions;
images_num = imageurl.length();
loadContent();
}
function loadContent():void{
var picRequest: URLRequest = new URLRequest(imageurl[n]);
var picLoader2 = new Loader();
picLoader2.load(picRequest);
picLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, picLoaded);
picLoader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, erLoaded);
}
function erLoaded(event: IOErrorEvent): void {
trace("error");
}
public function picLoaded(e: Event): void {
loadedPics.push(e.target.content);
var images_num_str:String = images_num.toString();
var zet:int = n+1;
var n_str:String = zet.toString();
loadingMenu.mytxt.text = "Loaded " + n_str + " / " + images_num_str;
if(n == images_num - 1){
for(var i:uint = 0; i < images_num; i++){
menuElement = new MenuBTN;
menuHolder.mouseChildren = true;
menuElement.idn = listId[i];
menuElement.link = "myfile.swf";
menuElement.tag = i;
menuElement.title.text = captions[i].toString();
menuElement.buttonMode = true;
menuElement.useHandCursor = true;
menuElement.mouseChildren = false;
menuElement.addEventListener(MouseEvent.CLICK, onClick);
menuElement.addEventListener(MouseEvent.MOUSE_UP, onMouseMove);
menuElement.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
menuElement.x = 130 + (i * 460 - xVal);
repNum++;
if(menuElement.x > 1550){
yVal += 550;
menuElement.x = 130;
xVal = i * 460;
}
var myTween: Tween = new Tween(menuElement, "y", Bounce.easeOut, 700, yVal, 2.5, true);
trace(menuElement.x);
menuHolder.addChild(menuElement);
menuElement.imgContainer.addChild(loadedPics[i]);
loadingMenu.mytxt.text = "Loading"
loadingMenu.visible = false;
}
}
else{
n++;
loadContent();
}
Copy link to clipboard
Copied
I think the slowness is that you are waiting for an http request to complete. You should be able to safely have six of those going on at the same time. Try doing your loadContent() six times at the start, and see if it is quicker.
Copy link to clipboard
Copied
It is noticeably shorter, but it creates additional blank containers on the stage.
Copy link to clipboard
Copied
Can you do the addchild steps at the same time as you add the listeners? That is, don't show any of them until all are downloaded.