Making a preloader in CS3

  • VictorEremita
  • Newbie
  • Newbie
  • VictorEremita
  • Posts: 10

Post 3+ Months Ago

I wanted to make a preloader for a flash movie with sound but I have quite a lot of trouble doing it. I'm using flash CS3.

I found this tutorial about how to make one - http://www.oreillynet.com/pub/a/oreilly ... _0501.html - but I got stuck already at step 8 where it says "Use Modify-->Frame to label the new keyframe loading". When I click Modify in CS3, there's nothing called Frame in there. So I was unable to follow the rest of the tutorial.

Well, the tutorial is, after all, made for Flash 5 so I searched the internet for a tutorial telling me how to make a preloader in CS3. But all the tutorials I was able to find was for Actionscript 3. I made my flash document in Actionscript 2 because I heard there were some advantages to Actionscript 2 that suited what I had in mind for the document. At this point, since I'm a noob, I don't understand the difference between actionscript 2 and 3 that much.

So how can I make a preloader in CS3 with actionscript 2?

Thank you!
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23460
  • Loc: Woodbridge VA

Post 3+ Months Ago

See if this helps you.
http://biochimistu.blogspot.com/2008/02 ... as-20.html
  • VictorEremita
  • Newbie
  • Newbie
  • VictorEremita
  • Posts: 10

Post 3+ Months Ago

ATNO/TW wrote:
See if this helps you.
http://biochimistu.blogspot.com/2008/02 ... as-20.html


Strange result. I followed his tutorial but with my existing document. I created the layers he told about and inserted the script in the first frame. Then I moved my own movie-layers to the second frame. Ok, then I should see the loading screen at frame 1 and it is only supposed to continue to frame 2 (where my movie begins) when it has loaded it all. After loading, it does indeed continue to the second frame but then nothing happens. It's just stuck at the second frame. I have no idea why it suddently won't play the movie after following his advice. I even tried to insert play(); in the second frame and a lot of things - but no, after loading I just see the second frame and nothing else.

And when looking at the code I don't understand it. The this.gotoAndPlay(2); should definatly make the movie play from there (no actions stops it at frame 2).

I'm confused. But thanks so far.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23460
  • Loc: Woodbridge VA

Post 3+ Months Ago

Humor me and instead of gotoAndPlay(2) try gotoAndStop(2)

I solved this problem yesterday the same way
flash-forum/problem-programming-flash-and-actionscript-t89436.html

gotoAndPlay, wouldn't work, but gotoAndStop did.
  • Xarathal
  • Born
  • Born
  • User avatar
  • Posts: 3

Post 3+ Months Ago

Here's the code I use. Basically, I create a movie clip called "mcPreloader", make sure it has 100 frames in it, put it on the root timeline, and then put the following code inside mcPreloader:

Code: [ Select ]
 
/************************************************************************
Preloader by http://www.TheCosmonaut.com
Modified from source code from Chris Sessions
Preloader movie clip must have 100 frames
************************************************************************/
//-- stop the parent movie
this._parent.stop();
//-- Define the name of the start frame. You can change this to be anything (a frame number or a frame name). Whatever it is, it refers to the frame of the main movie clip you want to play when the preloader is finished preloading.
var startFrame = "main";
//-- preload function
var preloadCounter:Boolean = false;
function preload(cutoffPercent:Number) {
    var totalBytes:Number = 0;
    var loadedBytes:Number = 0;
    //-- add parent bytes to total  
    totalBytes += Math.round(this._parent.getBytesTotal()/1024);
    loadedBytes += Math.round(this._parent.getBytesLoaded()/1024);
    //-- calculate percent done
    var percentDone = Math.round((loadedBytes/totalBytes)*cutoffPercent);
    if (loadedBytes>=totalBytes) {
        if (preloadCounter == false) {
            percentDone = 0;
            preloadCounter = true;
        } else {
            this.stop();
            delete(this.onEnterFrame);
            this._parent.gotoAndPlay(startFrame);
        }
    } else {
        this.gotoAndStop(percentDone);
    }
}
//-- start the function
this.onEnterFrame = function() {
    preload(100);
};
 
  1.  
  2. /************************************************************************
  3. Preloader by http://www.TheCosmonaut.com
  4. Modified from source code from Chris Sessions
  5. Preloader movie clip must have 100 frames
  6. ************************************************************************/
  7. //-- stop the parent movie
  8. this._parent.stop();
  9. //-- Define the name of the start frame. You can change this to be anything (a frame number or a frame name). Whatever it is, it refers to the frame of the main movie clip you want to play when the preloader is finished preloading.
  10. var startFrame = "main";
  11. //-- preload function
  12. var preloadCounter:Boolean = false;
  13. function preload(cutoffPercent:Number) {
  14.     var totalBytes:Number = 0;
  15.     var loadedBytes:Number = 0;
  16.     //-- add parent bytes to total  
  17.     totalBytes += Math.round(this._parent.getBytesTotal()/1024);
  18.     loadedBytes += Math.round(this._parent.getBytesLoaded()/1024);
  19.     //-- calculate percent done
  20.     var percentDone = Math.round((loadedBytes/totalBytes)*cutoffPercent);
  21.     if (loadedBytes>=totalBytes) {
  22.         if (preloadCounter == false) {
  23.             percentDone = 0;
  24.             preloadCounter = true;
  25.         } else {
  26.             this.stop();
  27.             delete(this.onEnterFrame);
  28.             this._parent.gotoAndPlay(startFrame);
  29.         }
  30.     } else {
  31.         this.gotoAndStop(percentDone);
  32.     }
  33. }
  34. //-- start the function
  35. this.onEnterFrame = function() {
  36.     preload(100);
  37. };
  38.  


I like this code because you can do more elaborate things inside the preloader (like have movie clips inside the preloader that trigger when a specific frame is reached).

Rock on!

--eric
  • VictorEremita
  • Newbie
  • Newbie
  • VictorEremita
  • Posts: 10

Post 3+ Months Ago

Thanks man!

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.