Jump to content
Search Community

Preloaders for all loading objects

fried test
Moderator Tag

Recommended Posts

Hi there,

 

My main swf has a few thumbnails for external swf's that need to load. The external swf's have been added to a Loadermax queue. Once the first swf loads, the others carry on loading in the background.

I would like to show the current progress of each of the swf's with a small progress bar above the thumbnails.

How would I go about this?

 

A point in the right direction would be appreciated.

 

Thanks.

Link to comment
Share on other sites

Sure, every loader dispatches PROGRESS events, so you can either addEventListener() to each one or use the "onProgress" shortcut like:

 

var queue:LoaderMax = new LoaderMax({onProgress:queueProgress});
queue.append( new SWFLoader("child1.swf", {onProgress:child1Progress}) );
queue.append( new SWFLoader("child2.swf", {onProgress:child2Progress}) );
queue.load();

function queueProgress(event:LoaderEvent):void {
   queueProgressBar.scaleX = event.target.progress;
}

function child1Progress(event:LoaderEvent):void {
   child1ProgressBar.scaleX = event.target.progress;
}

function child2Progress(event:LoaderEvent):void {
   child2ProgressBar.scaleX = event.target.progress;
}

 

Make sense?

Link to comment
Share on other sites

I still can't get it right. :(

I think this this code has me beat. I may be overlooking something really simple and/or have been staring at the code for too long.

 

Here are two main snippets of code:

for(var i:uint = 0; i	{
	pages.push(new SWFLoader(urls[i],{container:container_mc,name:"swf"+i,x:(1786)*i,y:yPos}));
	loaders = LoaderMax.getLoader(urls[i]);
	loaders.addEventListener(LoaderEvent.PROGRESS, childProgress)
	trace("Laoders :", loaders);
}

 

and the handler:

 

function childProgress(e:LoaderEvent):void
{
trace(e.target.progress);	
for(var z:uint = 0; z	{
	smallLoaderArray[z].scaleX = e.target.progress;
}
}

 

The smallLoaderArray is an array of the preloaders above the thumbnails. When the code executes, it scales the preloaders, but all of them show the progress of the first item, then the progress of the second, third etc.

 

As stated, I would like each of them to show the progress of their corresponding loader item.

 

Also, a quick question about maxConnections. What is a safe number of maxConnections to run simultaneously or doesn't it matter?

 

Thanks in advance.

 

*edit* I have tried numerous solutions in the handler, but to no avail...

Link to comment
Share on other sites

First of all, you could simplify your first block of code by using the onProgress shortcut to add your listener:

 

for (var i:int = 0; i       pages.push(new SWFLoader(urls[i],{container:container_mc, name:"swf"+i, onProgress:childProgress, x:(1786)*i, y:yPos}));
}

 

Your code would work fine, though (the first block). I just wanted to show you a way to simplify it.

 

The bigger problem has to do with your 2nd block of code. Every time any of the loaders dispatches a progress event, you're looping through ALL of the smallLoaders in the array and making them display that one loader's progress (which is precisely what you described). Don't do that :) You need to only adjust that one smallLoader's progress. So you need a way to associate each smallLoader with its particular SWFLoader instance. I wouldn't necessarily recommend structuring things this way, but if your smallLoaderArray has the same number of elements as your pages array and the order of the elements is synced up (smallLoaderArray[0] is for pages[0], etc.), then you could do something like this:

 

function childProgress(e:LoaderEvent):void {
   var index:int = pages.indexOf(e.target);
   smallLoaderArray[index].scaleX = e.target.progress;
}

 

Another option is to store a reference to the smallLoader inside the SWFLoader's vars object so that you can look it up quickly, kinda like:

 

for (var i:int = 0; i       pages.push(new SWFLoader(urls[i],{container:container_mc, name:"swf"+i, onProgress:childProgress, x:(1786)*i, y:yPos, smallLoader:smallLoaderArray[i]}));
}

function childProgress(e:LoaderEvent):void {
   e.target.vars.smallLoader.scaleX = e.target.progress;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...