9 Replies Latest reply on Jul 9, 2009 12:33 PM by kglad

    preloader problem with random image loader

    heazle

      I would like for the website preloader to recognize the random image loader that I have on frame 8 of my site

      I have a basic preloader on frames 1 and 2

      (frame 1)

                    var amountLoaded:Number=_root.getBytesLoaded()/root.getBytesTotal;

      (frame 2)

                    if(_root.getBytesLoaded()==_root.getBytesTotal()}

                    gotoAndStop(8);)\\\\beginnig of site

                    else (gotoAndPlay(1);}

      I have tried putting the random image loader on frame 1 or 8 and the preloader doeas not recognize it

      The random image loader is an empty movieclip that is in the center of the screen and has has code on frame 1 of it and an object with an instance name of location.

                    choise=Math.round(Math.random()*16);

                    switch (choise)  {

                    case 0:

                               location.loadMovie("image1.jpg")

                               break;

                    case 1:

                               location.loadMovie("image2.jpg")

                               break;          \\\\\\\and so on.

       

      the random image loader works great besides the fact that I cant get the preloader to recognize it

        • 1. Re: preloader problem with random image loader
          kglad Adobe Community Professional & MVP

          you'll need to create separate preloader code for the image loader.

          • 2. Re: preloader problem with random image loader
            heazle Level 1

            Do I put that code in the movie clip with the random image code?

            • 3. Re: preloader problem with random image loader
              kglad Adobe Community Professional & MVP

              put the preloader code in the same frame with the location.loadMovie() code.

              • 4. Re: preloader problem with random image loader
                heazle Level 1

                It didn't work but Im sure my code is off

                This is what I have in the first frame of the movie clip

                choice = Math.round(Math.random()*16);

                switch (choice) {

                     case 0 :

                          location.loadMovie("image0.jpg");

                          break;

                     case 1 :

                          location.loadMovie("image1.jpg");

                          break;

                      

                     case 16 :

                          location.loadMovie("image16.jpg");

                          break;

                           

                }

                var amountLoaded:Number= _root.getBytesLoaded()/root.getBytesTotal;

                if(_root.getBytesLoaded() == _root.getBytesTotal())

                {

                     _parent.gotoAndStop(8);

                }

                else {

                     gotoAndPlay(1);

                }

                • 5. Re: preloader problem with random image loader
                  kglad Adobe Community Professional & MVP

                  choice = Math.round(Math.random()*16);

                  switch (choice) {

                       case 0 :

                            location.loadMovie(" image0.jpg");

                            break;

                       case 1 :

                            location.loadMovie(" image1.jpg");

                            break;

                   

                       case 16 :

                            location.loadMovie(" image16.jpg");

                            break;

                   

                  }

                   

                  clearInterval(preloadI);

                  preloadI=setInterval(preloadF,100);

                   

                  function preloadF(){

                  var amountLoaded:Number= location.getBytesLoaded()/location.getBytesTotal;

                  if(amountLoaded==1)

                  {

                  clearInterval(preloadI);

                  // loading is complete.  do whatever.

                  }

                  else {

                  // loading is not complete.  display preload info/graphics

                  }

                  }

                  • 6. Re: preloader problem with random image loader
                    heazle Level 1

                    This is what I entered

                    Flash didn't like the

                      Function preloadF()

                     

                     

                    clearInterval(preloadI);

                    preloadI=setInterval(preloadF,100);

                    function preloadF(){

                    var amountLoaded:Number=

                    location.getBytesLoaded()/location.getBytesTotal;

                    if(amountLoaded==1)

                    {_parent.gotoAndStop(8);

                    clearInterval(preloadI);

                    }

                    else {gotoAndPlay(1);}

                    • 7. Re: preloader problem with random image loader
                      kglad Adobe Community Professional & MVP

                      1.  it looks like you missed a function closure - }

                       

                      2.  don't use a frame loop with that code.

                      • 8. Re: preloader problem with random image loader
                        heazle Level 1

                        I think I almost have it, the only thing I am having trouble figuring out is the else {} I want it to play a movie clip "preload 1" in the right x, y corrdinate

                        And I want it to goto fame 8 of the parent movie clip whan done.

                         

                         

                        choice = Math.round(Math.random()*16);

                        switch (choice) {

                             case 0 :

                                  location.loadMovie("Simage0.jpg");

                                  break;

                             case 1 :

                                  location.loadMovie("Simage1.jpg");

                                  break;

                              

                             case 16 :

                                  location.loadMovie("Simage16.jpg");

                                  break;

                                   

                        }

                        clearInterval(preloadI);

                        preloadI=setInterval(preloadF,100);

                        function preloadF(){

                        var amountLoaded:Number=

                        location.getBytesLoaded()/location.getBytesTotal;

                        }

                        if(amountLoaded==1)

                        {

                             _parent.gotoAndStop(8);

                        clearInterval(preloadI);

                        }

                        else {}

                        • 9. Re: preloader problem with random image loader
                          kglad Adobe Community Professional & MVP

                           

                           

                          choice = Math.round(Math.random()*16);

                          switch (choice) {

                               case 0 :

                                    location.loadMovie(" Simage0.jpg");

                                    break;

                               case 1 :

                                    location.loadMovie(" Simage1.jpg");

                                    break;

                           

                               case 16 :

                                    location.loadMovie(" Simage16.jpg");

                                    break;

                           

                          }

                          clearInterval(preloadI);

                          preloadI=setInterval(preloadF,100);

                          function preloadF(){

                          var amountLoaded:Number=

                          location.getBytesLoaded()/location.getBytesTotal;

                          }

                          if(amountLoaded==1)

                          {

                               _parent.gotoAndStop(8);

                          clearInterval(preloadI);

                          }

                          else { preload1.gotoAndStop(Math.ceil(100*amountLodaed))}}  // if preload1 has 100 frames and displays the load progress