|
-
Bearded (M|G)od
[F8] MovieClipLoader assistance
I know how to load clips/images with the MovieClipLoader class, but what I want to load is say 10 thumbnails and have one progressbar for all of the items, so itll say its done loading when all 10 thumbnails are loaded. Is there an easy way to do it? I've done it before by setting a variable for how many there are total, and after each onLoadComplete call, I add one to the variable until it reaches how many its supposed to do. basically i want to do this:
Code:
loader.load("image1.png");
loader.load("image2.png");
loader.load("image3.png");
loader.onAllFinished = function():Void
{
trace("all the images are loaded");
};
thanks in advance!
-
Senior Member
i had a project where i had to do somthing kinda the same, it might not be what you are looking for but ill give you my code
Code:
stop();
status_txt.text = "Loading Movie";
var movieTotal:Number = _root.getBytesTotal();
var movieLoaded:Number = _root.getBytesLoaded();
var precentLoaded:Number = ((_root.getBytesLoaded()/_root.getBytesTotal())*100);
var totalImages:Number = 6;
var totalLoaded:Number = 0;
preloader_mc.onEnterFrame = function(){
preloader_mc.progress_mc._xscale = precentLoaded/2;
if(precentLoaded == 100){
delete this.onEnterFrame;
loadIt();
status_txt.text = "Loading Slides";
}
}
this.createEmptyMovieClip("target_mc",-2);
target_mc._alpha = 0;
var mainLoader:MovieClipLoader = new MovieClipLoader();
var mainLoaderLis:Object = new Object();
mainLoaderLis.onLoadComplete = function(){
trace("loaded " + totalLoaded + " images");
preloader_mc.progress_mc._xscale += (50/totalImages);
loadIt();
};
mainLoader.addListener(mainLoaderLis);
function loadIt(){
if(totalLoaded == totalImages && movieLoaded == movieTotal){
gotoAndPlay("loaded");
return;
}else{
totalLoaded++;
mainLoader.loadClip("images/0"+totalLoaded+".jpg", target_mc);
}
};
-
Bearded (M|G)od
yeah, you're basically doing exactly what i was doing. I was looking for a more global thing for the moviecliploader instead of it only handling one at a time. thanks anyways. you reinforced what i was doing.
-
Flashmatics
-
Bearded (M|G)od
I think its time to write a class for this It'll incorporate a queue and on onAllLoadComplete method. I can see people needing this as do i! I'll post when im done.
-
Bearded (M|G)od
here we go:
Code:
//myMovieClipLoader class written by Matthew Robenolt
//(c)2006 YDEK Productions
//http://www.youdontevenknow.us
class us.youdontevenknow.myMovieClipLoader
{
private static var _queue:Array;
private static var mc_progresses:Array;
private static var mcLoader:MovieClipLoader;
private static var mcLoaderListener:Object;
private static var howManyLoaded:Number = 0;
private static var howManyStarted:Number = 0;
private static var ids:Array;
private static var currentLoadedBytes:Number = 0;
private static var currentTotalBytes:Number = 0;
private static var startLoadTime:Number;
private static var loadDuration:Number;
private static var _onAllLoadComplete:Function;
private static var _onAllLoadProgress:Function;
public function myMovieClipLoader()
{
_queue = new Array();
mc_progresses = new Array();
ids = new Array();
mcLoader = new MovieClipLoader();
mcLoaderListener = new Object();
mcLoader.addListener(mcLoaderListener);
mcLoaderListener.onLoadComplete = oneLoaded;
mcLoaderListener.onLoadProgress = updateProgress;
mcLoaderListener.onLoadStart = downloadStarted;
}
private function downloadStarted(target_mc:MovieClip):Void
{
ids.push(String(target_mc));
mc_progresses[ids.length-1] = {downloaded:0, total:0};
howManyStarted++;
}
private function oneLoaded():Void
{
howManyLoaded++;
//trace("loaded so far: "+howManyLoaded +"/"+_queue.length);
if (howManyLoaded == _queue.length)
{
loadDuration = getTimer() - startLoadTime;
_onAllLoadComplete(loadDuration);
}
}
private function updateProgress(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void
{
var currentid:Number = 0;
for (var i:Number = 0; i < ids.length; i++)
{
if (ids[i] == String(target_mc))
{
currentid = i;
break;
}
}
mc_progresses[currentid].downloaded = bytesLoaded;
mc_progresses[currentid].total = bytesTotal;
currentLoadedBytes = 0;
currentTotalBytes = 0;
for (var i:Number = 0; i < ids.length; i++)
{
currentLoadedBytes += mc_progresses[i].downloaded;
currentTotalBytes += mc_progresses[i].total;
}
_onAllLoadProgress(currentLoadedBytes, currentTotalBytes);
}
public function addToQueue(_filename:String, _target_mc:MovieClip):Void
{
//trace(_filename+" added to queue");
_queue.push({filename:_filename, target_mc:_target_mc});
}
public function loadAll():Void
{
if (_queue.length > 0)
{
howManyLoaded = 0;
startLoadTime = getTimer();
for (var i:Number = 0; i < _queue.length; i++)
{
mcLoader.loadClip(_queue[i].filename, _queue[i].target_mc);
}
}
else
{
trace("no items in queue!");
}
}
public function set onAllLoadComplete(func:Function):Void
{
_onAllLoadComplete = func;
}
public function set onAllLoadProgress(func:Function):Void
{
_onAllLoadProgress = func;
}
}
here is how its used:
Code:
import us.youdontevenknow.myMovieClipLoader;
var loader:myMovieClipLoader = new myMovieClipLoader();
loader.addToQueue("image1.png", target1_mc);
loader.addToQueue("image2.png", target2_mc);
loader.addToQueue("image3.png", target3_mc);
loader.loadAll();
loader.onAllLoadComplete = function(loadDuration:Number):Void
{
trace("all loaded in "+loadDuration+"ms");
};
loader.onAllLoadProgress = function(bytesLoaded:Number, bytesTotal:Number):Void
{
trace("loading..."+Math.round((bytesLoaded/bytesTotal)*100)+"%");
};
if anyone has any suggestions for a feature or improvement, lemme know and ill add it 
ps] sorry if the code is a bit sloppy. i havent completely cleaned it up yet or optimized it. i just got it to work! feel free to use it!
Last edited by MyFriendIsATaco; 10-31-2006 at 02:48 AM.
-
Bearded (M|G)od
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|