Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preloader for al swf-s that willl be used

Status
Not open for further replies.

brutteforcce

Technical User
Jun 23, 2006
105
RO
I use a lot in my site a movie clip loader called myMCL. Every time it loads something the preloader is working. Firt I thought that it is a good idea but now I want that preloader to preload all the swf-s that I load using the movie clip loader...

stop();
//--------------------<MCL>-----------------------\\
var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();

myMCL.addListener(myListener);

myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
_level50._visible = true;
var preloadPercent:Number = Math.round((loadedBytes / totalBytes) * 100);
_level50.preloader.gotoAndStop(preloadPercent);
}

myListener.onLoadComplete = function(target_mc:MovieClip) {
_level50._visible = false;
}
//--------------------</MCL>-----------------------\\

// trigger the MCL to load these assets:
myMCL.loadClip("trigger.swf", 5);
myMCL.loadClip("preloader.swf", 50);

Please help... Thanks!
 
Until the preloader is preloaded I want to put a text like: "Loading..." with the font _sans... That text will apear very quick so I don't need another preloader for the preloader...
How can I do the preloading of the preloader? I need to create a new MovieClipLoader and a listener for it?
Please help me...
Thanks...
 
The easiest way is put "if this.getBytesLoaded() >= this.getBytesTotal() then gotoAndStop(2)" script in the frame 1, then put the sequential loading script in frame 2, and put your actual code in frame 3 onwards.

Kenneth Kawamoto
 
Thanks...
So I have:
Frame 1 action script:
Code:
if (this.getBytesLoaded() >= this.getBytesTotal()) {
	gotoAndStop(2);
}

Frame 2 action script:
Code:
// AS2 main timeline
var swfList:Array = ["main_menu.swf", "initial.swf", "static.swf","links/link1.swf","links/link2.swf","links/link3.swf","links/link4.swf","submeniu/submeniu1.swf", "submeniu/centraleTermice/centrala1.swf", "trigger.swf"];
var swfBytesList:Array = new Array();
var loadID:Number = 0;
var isTestLoad:Boolean = true;
var grossBytes:Number = 0;
var bytesCompleted:Number = 0;
var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myMCL.addListener(myListener);
myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number):Void  {
    if (isTestLoad) {
        if (totalBytes) {
            swfBytesList.push(totalBytes);
            trace("SWF: "+target_mc._url);
            trace("totalBytes: "+totalBytes);
            grossBytes += totalBytes;
            trace("grossBytes so far: "+grossBytes);
            trace("***");
            loadID++;
            if (loadID<swfList.length) {
                testLoad(loadID);
            } else {
                trace("Final grossBytes: "+grossBytes);
                trace("***");
                myMCL.unloadClip(mcTemp);
                mcTemp.removeMovieClip();
                trace("Start sequential loading");
                trace("***");
                isTestLoad = false;
                loadID = 0;
                sequentialLoad(loadID);
            }
        }
    } else {
        trace("Currently loading "+target_mc._url);
        var bytesSoFar:Number = bytesCompleted+loadedBytes;
        trace("Bytes loaded so far: "+bytesSoFar);
        var percentageLoaded:Number = Math.floor(10000*bytesSoFar/grossBytes)/100;
        _level50.preloader.gotoAndStop(percentageLoaded);
		trace(percentageLoaded+"%");
        trace("***");
    }
};
myListener.onLoadComplete = function(targetMC:MovieClip, httpStatus:Number):Void  {
    targetMC._visible = false;
	bytesCompleted += swfBytesList[loadID];
    trace("Load completed for "+targetMC._url);
    trace("***");
    loadID++;
    if (loadID>=swfList.length) {
        trace("All loadings completed!");
		myMCL.removeListener(myListener);
		gotoAndStop(3);
		
	} else {
        sequentialLoad(loadID);
    }
};
function sequentialLoad(loadID:Number):Void {
    var ID:Number = loadID+1;
    var mc:MovieClip = this.createEmptyMovieClip("mc"+ID, ID);
    myMCL.loadClip(swfList[loadID], mc);
}
function testLoad(loadID:Number):Void {
    mcTemp.removeMovieClip();
    this.createEmptyMovieClip("mcTemp", 1);
    myMCL.loadClip(swfList[loadID], mcTemp);
}
testLoad(loadID);

stop();
//

Frame 3 Action Script:
Code:
//------------------<LoadVars>---------------------\\
var myLV:LoadVars = new LoadVars();

myLV.onLoad = function (success) {
	if (success) {
		_level5.loadedInfo.htmlText = myLV.info;
	} else {
		_level5.loadedInfo.text = "There has been an error loading the requested information. Please contact the Webmaster and report your error.";
	}
}
//------------------</LoadVars>---------------------\\

_level50._visible = false;
myMCL.loadClip("main_menu.swf", 10);
myMCL.loadClip("initial.swf", 5);
myMCL.loadClip("static.swf", 20);
stop();

Of course it doesn't work because I don't load preloader.swf. I tryed to load it in different ways and when I made a simulate download to see if it is working Flash crashed...
Where should I put the loading of the preloader? I would like the action
"_level50.preloader.gotoAndStop(percentageLoaded);"
to be functional... Please help me...
Thanks a lot...
 
Do you mean you want to load "preloader.swf" into _level50 in frame 1, then when it's loaded move on to the frame 2? If so you can do something like:

[tt]//
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(this);
this.onLoadInit = function():Void {
gotoAndStop(2);
delete this.onLoadInit;
};
mcl.loadClip("preloader.swf", 50);
stop();
//[/tt]

However as I said before your "preloader.swf" should be small and load almost instantly, you shouldn't need this type of script - a loader for a loader!

Kenneth Kawamoto
 
Thanks...
preloader.swf has 1.48 kb. When the list of swf-s begins preloading I have to be shore the preloader is loaded because I use the action
_level50.preloader.gotoAndStop(percentageLoaded);
Evrything should work fine... The site works normally, but I can test the downloading, when I press simulate download Flash crashes... What could be the problem?
 
Sorry... I wanted to say that I can't test the preloading of the site...
 
Maybe the external swf-s make Flash crash with the script that you helped me build. Using my previsorious script the simulate works fine, evry time when I load something the preloader begins preloading when a swf is loaded in a level, that's why I wanted all the loading at the begining, for example I have 3 swf-s that must be shown at the same time but there are shown 3 preloaders one after another and the sws-s apear exactly after the loading ( not all at the same time ).
The script is:

stop();
//--------------------<MCL>-----------------------\\
var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();

myMCL.addListener(myListener);

myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
_level50._visible = true;
var preloadPercent:Number = Math.round((loadedBytes / totalBytes) * 100);
_level50.preloader.gotoAndStop(preloadPercent);
}

myListener.onLoadComplete = function(target_mc:MovieClip) {
_level50._visible = false;
}
//--------------------</MCL>-----------------------\\

// trigger the MCL to load these assets:
myMCL.loadClip("trigger.swf", 5);
myMCL.loadClip("preloader.swf", 50);

//------------------<LoadVars>---------------------\\
var myLV:LoadVars = new LoadVars();

myLV.onLoad = function (success) {
if (success) {
_level5.loadedInfo.htmlText = myLV.info;
} else {
_level5.loadedInfo.text = "There has been an error loading the requested information. Please contact the Webmaster and report your error.";
}
}
//------------------</LoadVars>---------------------\\

Are you shore that code isn't making Flash to give the send, don't send error? Can you make a quick test with you're code please?
Thanks..
 
Your code above is where you were at the beginning.

You're right though, it crashes if you do "Simulate Download" while "Test movie" works fine.

I had a quick look around on the net, and found some people reported there are issues with MovieClipLoader class and the "Simulate Download" feature in Flash, but couldn't find anything concrete. I will contact Adobe to see if I get any answer from them on this!

Kenneth Kawamoto
 
Thanks a lot!!!
So, it is possible that the site will work fine on the Internet? I will make a try, eaven so the simulate download should work fine, thank you very much again...

I see you are a very good Flash programmer and I would like to start learning Flash seriously, from the beginig, can you advice me where should I get started? I hope I can learn something this year but maybe I will start next one because now I have a lot of learning for the exam ( I'm 8th grade )...
 
It should work fine in the real environment even it crashes in the simulate download mode - there's something dodgy in the simulate download feature in Flash, I reckon...!

Yeah you can start with the next one, Flash 9 - completely new ActionScript 3 runs on completely re-written super fast ActionScript Virtual Machine 2. I should start learning it too - hope my brain can still handle all these new things!!

Kenneth Kawamoto
 
Thank you. I put the site on a free host. It is 75 kb so I can't see the preloading ( my internet conection is fast ), but it didn't worked well, the first time when something should load it apears after a couple of seconds and the next time I load the same thing it apears instantly.
I think I will start with Action Script 3, thanks for the advice and I'm shore you can learn it cause you are a very smart guy...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top