Flash Tip 1: Preloader Doesn’t Work? It Might Be Your Sounds

September 15th, 2007

FlashI made a goofy Gilmore Girls video game and then realized I messed something up that causes the preloader to not display right away - defeating the whole purpose of a preloader.

Note: This is all in the ActionScript 2.0 world - I’m still getting up to speed in ActionScript 3.0…

When dynamically loading and playing sounds in ActionScript, you may have correctly set your sound file in the library to Export for ActionScript and Export in first frame. It’s the latter item that messes things up. It seems Flash takes that first frame thing literally and will load those library items even before the ActionScript you have on frame one, layer one - which is usually your preloader code.

One way around this is to force Flash to load the sound files after the first frame but before the frame they’re needed. Here are the steps to do so:

  1. Decide on a frame to load your sounds into that’s after frame 1 but before the main body of your movie - the obvious choice is frame 2.
  2. Change your preloader code that’s on frame 1 to skip frame 2 and go to the actual body of your movie after everything has loaded.
  3. Select your sound files one by one in the library and uncheck “Export in first frame”.
  4. Select frame 2. Insert a blank movie clip on the Stage (Insert -> New Symbol)
  5. Open up that blank movie clip. On frame one, add a stop(); action.
  6. Create a keyframe on frame 2 of this blank movie clip. In the Properties Inspector, set the sound drop down menu to one of the sounds in your library that you need to load early.
  7. Repeat steps 4 through 7 for all your sounds in the library.

Essentially the deal here is you’re putting all your sounds into “dummy” movie clips hanging out on frame 2. But because of the ActionScript edits in the preloader and the stop(); in the dummy movie clips, your movie will never play those sounds - but it will load them.

Now test your movie - especially with the download manager at some ridiculously low bandwidth settings - and your preloader should function as it should.

4 comments!

  1. comment Gravatar sam - January 7th, 2008

    Thank you for the tutorial, I was banging my head the wall trying to figure out why the preloader wasn’t working.

    Much appreciated,

    -Sam

  2. comment Gravatar jon - January 7th, 2008

    What if the sounds will be dynamically attached via the attachSound function?
    It seems that I HAVE to Export in First Frame in that case.

  3. comment Gravatar jon - January 7th, 2008

    Woohoo…I won the contest..right on.
    I found the solution to my question at this site here:
    http://www.kennybellew.com/tutorial/preload_attachsound.htm

  4. comment Gravatar Webomatica Contest 4: Leave Comment 4,000 And Win 40 Bucks » Webomatica - Technology and Entertainment Digest - January 7th, 2008

    [...] The contest is over - Jon left the winning comment on an old Flash tips post. Congrats to Jon and I believe he was a total “drive by” visitor to the blog who had no [...]

Please comment!