[osflash] MTASC & Preloading

Daniel Castro codedface at gmail.com
Tue Jul 11 01:48:28 EDT 2006


Hello,
I got this code from a tutorial a while back (I can't find). Just:
1) Copy paste this code in the first frame.
2) Name your instance (I named mine "myProgressBar")
3) Use the command that fits your needs. I have frame 3 named "run", so I
call gotoAndPlay("run");
4) Add a flash preloader component from your component window.
That did the job for me! Check what it looks like @ http://mostazamedia.com/

 //Copy Paste
 // Create a listener object event function. The progress bar is an object
so it needs an object function to work
      myProgressBarListener = new Object();

      // When the progress bar is complete and has preloaded this movie, the
listener will call and run this code below:
      myProgressBarListener = function (eventObject) {

          // Hide the progress bar now as we don't need it any more
          myProgressBar._visible = false;

          // In this example I have used the gotoandstop(); command because
I want the movie to go to and stop at frame 2
          //gotoAndStop(2);

          // As an alternative remove the line above and un-comment any of
the code below:

          // This will go to the next frame but may not automatically play
beyond the next frame:
          // nextFrame();

          // This will go to the next scene but may not automatically play
beyond the first frame in the next scene:
          // nextScene();

          // Replace the X with the frame number you want the Movie to go to
and stop:
          // gotoAndStop(X);

          // Replace the X with the frame number you want the Movie to go to
and play:
          // gotoAndPlay(X);

          // When referring to frame labels ensure that the label name is in
quotes in the code:
             gotoAndPlay("run");

    // Close the above function
    };


    // Declares a listener that detects when the progress component has
loaded the movie and is complete. Then calls the function above:
myProgressBarListener
    myProgressBar.addEventListener("complete", myProgressBarListener);

    // We are now setting the progress bar component variables
    // Set up the progress bar component to polled when loading the movie.
In this case it has to be set to polled to work
    myProgressBar.mode = "polled";

    // Set the location to load as this movie.
    myProgressBar.source = "_root";

    // Set the conversion to 1. This basically means the component divides
the current and total values loaded and to be loaded. Then it floors them
(works out the difference between them) and displays the converted value in
the label property
    myProgressBar.conversion = "1";

    // Set the label to display the word 'loading' followed by the
percentage value loaded so far
    myProgressBar.label = "LOADING %3%%";

    // The direction the progress bar moves when loading
    myProgressBar.direction = "right";

    // The location of the label that displays the percentage loaded so far
    myProgressBar.labelPlacement = "bottom";

    // Stops the Movie at the current frame until the Movie has been
preloaded
    stop();

//=====================================================
//CODE ENDS


On 7/10/06, mail at tonio.com <mail at tonio.com> wrote:
>
> Hello,
>
> I have a simple Noob question. Sorry if it's been covered.
>
> If I'm building a big AS2 project with MTASC do I need some kind of
> preloader? If so what's the best practice?
>
> At a guess I have:
>
> import mx.utils.Delegate;
>
> class MyRun extends MovieClip{
>
>           var intID:Number;
>
>           function MyRun(mc){
>                    mc.__proto__ = this.__proto__;
>                 mc.__constructor__ =  Gogo;
>                 this = mc;
>
>                    intID = setInterval(Delegate.create(this, preLoad),
> 100);
>           }
>
>           function preLoad():Void
>           {
>               if (getBytesLoaded()==getBytesTotal()){
>                   clearInterval(intID);
>                   postLoad();
>               } else {
>                   //loading widget
>               }
>           }
>
>           function postLoad():Void
>           {
>               //run
>           }
>
>         public static function main() : Void
>         {
>                Stage.align = "TL";
>                Stage.scaleMode = "noScale";
>                var doIt:MyRun = new MyRun(_root);
>         }
> }
>
> _______________________________________________
> osflash mailing list
> osflash at osflash.org
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/osflash_osflash.org/attachments/20060710/121f270f/attachment-0001.htm


More information about the osflash mailing list