Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Sequential Preload, nothing is better than happy visitor
Rating 5 V
cybernetix
post Oct 12 2004, 04:14 AM
Post #1


ReloadeD
Group Icon
Group: Honored
Posts: 562
Joined: 20-May 04
From: Belgrade, Serbia
Member No.: 17





well, sometime you have several files that must be loaded in mainMovie, earlier or later. it is better earlier shades.gif

suppose that you have mainMovie with some subMovies to load, and when mainMovie starts it waits for user action and then loads subMovie in accordance with user action.

would'nt it be nice to preload subMovies in background while user reads main page?

is it possbile ?

YES !

let's see how it can be done ohmy.gif

CODE
onload() { // by cybernetix 13dots.com

// let's create some nice object which will hold everything
// MUST BE A GLOBAL VAR
    _global.ploader=new Object();
    
    // quey for movies to load
    ploader.quey=new Array();
    
    // quey for loaded movies
    ploader.loadedMovies=new Array();
    
    // ok, we have to load files somewhere, so xml will be fine :)
    // yes, IT IS POSSIBLE TO LOAD ANYTHING INTO XML OBJECT, BUT
    // IT DOES NOT MEAN that you can read it using xml methods.
    // in this case we shall use it just to load files in cache
    // for later quick use.
    ploader.loader=new XML();

    // function which will load files, one by one
    ploader.loadNext=function() {
        
        // let's see is there any file in a quey
        if ( this.quey.length > 0 ){
            
            // just to be sure that file exists, ANOTHER XML TRICK
            this.loader.onload=function(success) {
                
                // if file is loading parameter success will be TRUE
                // otherwise will be FALSE, so we are intersting in
                // only if it fails
                if (!success) {
                    // file not found, call function to let us know
                    // what is going on
                    ploader.ploaderHalted();                    
                }
            };    

            // load file
            this.loader.load(this.movieName=this.quey.shift());
            
            // call function dataControl with interval, just to control
            // what happens with loading. interval=100, you can change
            // it to whatever, but if you have small files it is better
            // to be short interval.
            this.intervaller = setInterval(this, "dataControl", 100);
            
        } else {
            
            // nice, all files loaded
            // remove this javascript line in your movie and place your action
            // eg. gotoSceneAndPlay("Scene_2",1);
            javascript("alert('ALL MOVIES PRELOADED')");
            
        }
    };
    
    // function which will tell us what is going on
    ploader.dataControl=function() {
        
        // let's see percetnage of loaded
        this.percent=this.loader.percentLoaded();
        
        // here you can display which file loads and percent of load
        /*
           someDynamicTextField_1.text=this.movieName;
           someDynamicTextField_2.text=this.percent;
        */

        // if loaded completely
        if (this.percent == 100) {
            // clear interval
            clearInterval(this.intervaller);
            // put this file in loaded area
            this.loadedMovies.push(this.movieName);
            // load next file
            this.loadNext();
        }
    };
    
    // function that will be invoked within loader.onload function
    // and will be used if some file can not be loaded
    ploader.ploaderHalted=function() {
        
        // can not load file, take some action here
        // remove this javascript line in your movie and place your action
         javascript(  "alert('CAN NOT LOAD MOVIE: '+'"+ploader.movieName+"')"  );

    };

    // this one will tell us if file is loaded
    // use it from anywhere like this
    /*
      if (ploader.isLoaded("file.swf or jpg or whatever")) {
          fine, it is loaded, do this
      }
      else {
          it is not loaded, do that
      }
    */
    // NOTE: it will return false if you pass to function file name
    // which is not listed in ploader.quey
    ploader.isLoaded=function(movieName) {
        
        // initiate control var
        ploader.movieLoaded=false;
        
        // let's have a look in loadedMovies
        for (i=0;i<ploader.loadedMovies.length;i++) {
            // if it is there, it is loaded
            if (ploader.loadedMovies[i]==movieName) {
                ploader.movieLoaded=true;
            }
        }
        
        // if not found in ploader.loadedMovies
        // var ploader.movieLoaded will remain false

        // now, return true or false
        return ploader.movieLoaded;
    };
    
    // here you should place files to preload in order as you wish
    ploader.quey.push("movie1.swf");
    ploader.quey.push("file1.txt");
    ploader.quey.push("image1.jpg");    
    
    // here we go, this one will start preloading
    ploader.loadNext();
    
    // NOTE - somewhere later you can destroy ploader object, to release memory
    // but ONLY if you decide to wait for all movies to preload, otherwise you
    // will need it later to know which one is loaded.
    /*
        ploader=undefined;
    */
}
// here is the point where you can decide if you want movie to wait for all
// movies to be preloaded first or you can remove stop(); so main movie will
// play while preloading other subMovies in background.
onFrame(1) {
    stop();
}
// with this preloader you can preload ALL KIND OF FILES.

//


just put this code in the _root, change file names in ploader.quey,
you can add some more of course and test it.
 
+Quote Post  Go to the top of the page
cybernetix
post Oct 12 2004, 12:01 PM
Post #2


ReloadeD
Group Icon
Group: Honored
Posts: 562
Joined: 20-May 04
From: Belgrade, Serbia
Member No.: 17





this one is more readable.

CODE
onload() { // by cybernetix 13dots.com
_global.ploader=new Object();
ploader.quey=new Array();
ploader.loadedMovies=new Array();
ploader.loader=new XML();
ploader.loadNext=function() {
if ( this.quey.length > 0 ){
this.loader.onload=function(success) {
if (!success) {
ploader.ploaderHalted();
}
};
this.loader.load(this.movieName=this.quey.shift());
this.intervaller = setInterval(this, "dataControl", 100);
} else {
javascript("alert('ALL MOVIES PRELOADED')");
}
};
ploader.dataControl=function() {
this.percent=this.loader.percentLoaded();
if (this.percent == 100) {
clearInterval(this.intervaller);
this.loadedMovies.push(this.movieName);
this.loadNext();
}
};
ploader.ploaderHalted=function() {
javascript( ?"alert('CAN NOT LOAD MOVIE: '+'"+ploader.movieName+"')" ?);
};
ploader.isLoaded=function(movieName) {
ploader.movieLoaded=false;
for (i=0;i<ploader.loadedMovies.length;i++) {
if (ploader.loadedMovies[i]==movieName) {
ploader.movieLoaded=true;
}
}
return ploader.movieLoaded;
};
ploader.quey.push("movie1.swf");
ploader.quey.push("file1.txt");
ploader.quey.push("image1.jpg");
ploader.loadNext();
}
onFrame(1) {
stop();
}
 
+Quote Post  Go to the top of the page
alejandrox
post May 27 2005, 04:49 PM
Post #3


New Member
Group Icon
Group: Member
Posts: 2
Joined: 27-May 05
Member No.: 4,339



How to make a preloader only with a bar ?
and
how to make a preloader only with a 0%....100% only numbers ?

i am learning swishmax, and i am from venezuela, i don´t speak english very good, but i cant to try!

Thanks friends
 
+Quote Post  Go to the top of the page
FurBunny
post Sep 2 2005, 12:38 PM
Post #4


New Member
Group Icon
Group: Member
Posts: 22
Joined: 23-May 05
From: Norway,Bergen
Member No.: 4,225





Geeeeezzzz, how long did it take u to do that, i mean ppl call me a geek,,but...well i bow in mere dazlment. If any gamers out there slap me around with a trout so i can wake up. If i ever get as good as u, im gonna be rich..hehe. Im allways amazed by ppl that actually know how to write code, ive tryed yes belive me ive tryed. Cheers the bunny, the furry one. =smile.gif
 
+Quote Post  Go to the top of the page
alias.infnit
post Sep 2 2005, 04:41 PM
Post #5


Ludwig Wendzich
Group Icon
Group: *Premier*
Posts: 1,243
Joined: 13-July 05
From: New Zealand
Member No.: 5,345





Yes, I'd love it if ALL flash/swish sites preloaded everything...nothing worse than clicking on a link and seeing loading - again!
 
+Quote Post  Go to the top of the page
mryes
post Mar 9 2006, 01:56 AM
Post #6


New Member
Group Icon
Group: Member
Posts: 10
Joined: 9-March 06
Member No.: 10,208





This preloader rocks
 
+Quote Post  Go to the top of the page
weidley
post Mar 12 2006, 06:08 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 7
Joined: 15-January 06
Member No.: 9,005





Hate preloaders, love this!
 
+Quote Post  Go to the top of the page
mohamed_anwar
post Mar 28 2006, 10:03 AM
Post #8


New Member
Group Icon
Group: Member
Posts: 13
Joined: 28-March 06
Member No.: 10,509





thank you very much
 
+Quote Post  Go to the top of the page
IcHi BaN
post Jan 23 2007, 08:28 PM
Post #9


New Member
Group Icon
Group: Member
Posts: 1
Joined: 5-October 05
Member No.: 7,373





Hi I noticed the Senquential Preloader (URL: http://www.13dots.com/forum/index.php?showtopic=2359) that you coded and put on on a post here. Wonderful, wonderful code. I was wondering though, I copied and pasted directly from the site and the first area (with the explanation) and when I checked for errors in the code i got the following:

CODE
**Error** Scene=Scene 1, layer=action, frame=1:Line 1: Syntax error.
onLoad() { // by cybernetix 13dots.com*
*Error** Scene=Scene 1, layer=action, frame=1:Line 139: Syntax error.
onFrame(1) {Total ActionScript Errors: 2 Reported Errors: 2


I havent chaned any of the code except for the file names in ploader.quey and onFrame area I replaced stop with gotoAndPlay.

Any idea why these two errors are popping up?

Im working on this major project right now and was hoping I could use this preloader for it. Any help would be GREATLY appreciated. Thanks!! thumbsup.gif

Jonathan

P.s. By the way, I am using Flash 2004MX Pro not Swish, does that change anything?

This post has been edited by IcHi BaN: Jan 23 2007, 08:29 PM
 
+Quote Post  Go to the top of the page
equali
post Jan 30 2007, 05:15 PM
Post #10


New Member
Group Icon
Group: Member
Posts: 1
Joined: 30-January 07
From: Altamont, NY
Member No.: 14,714





Thank You, thank you... awesome preloader.
 
+Quote Post  Go to the top of the page

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 29th July 2010 - 10:58 PM
Package Holidays | Life Insurance | Package Holidays | Broadband | Lyrics