Skip to main content
January 28, 2007
Question

I have a preloader, but...

  • January 28, 2007
  • 2 replies
  • 170 views
I have an mp3 file in a Flash movie using Flash MX.

The movie purely consists of the mp3 file and a stop and play button.

I would like the music (or movie) to play when 50% loaded and I am searching the net to find a way.

I already have a preloader which works perfectly using the following actionscript...but I'd like to know what to tweak in order to make the music (movie) play when 50% loaded. My current action script is as follows...



lBytes = _root.getBytesLoaded();
tBytes = _root.getBytesTotal();
percentLoaded = Math.floor((lBytes/tBytes)*100);
loader.bar._xscale = percentLoaded;
loader.percent.text = percentLoaded + "% of " + Math.floor(tBytes/1024) + "K loaded.";
if (lBytes>=tBytes && tBytes>0) {
if (count>=12) {
gotoAndStop("main");
} else {
count++;
gotoAndPlay("preload");
}
} else {
gotoAndPlay("preload");
}


....I know that there are other ways of playing mp3 on Flash (ie. Media Playback Component and a multitude of templates on the net) however I find that the Flash players that load the mp3 externally play at different speeds in different browers, so becuase of this I choose to have the mp3 located within the flash movie to avoid any inconsistancies amongst browsers. All I require is actionscript that makes the music (or movie) play when 50% loaded.

I'm gonna continue to search for an answer, and if I find a solution I will update my post.

Thanks!

You can see the swf file in the following htm page...

http://www.plobs.com/theme_song.htm
This topic has been closed for replies.

2 replies

January 29, 2007
Thanks for the info.

I tried the action script provided, but it didn't work...maybe I inserted it in the wrong place.

Anyhow, I am currently trying out your other suggestion. I'm in the process of creating the mp3 with 44HZ.

If that doesn't work (fingers crossed it will), I will have another play around with the action script.

Inspiring
January 29, 2007
the conditional test should be if(percentL >= 50) sorry. was tired writing this. lol. the current test would always fail. hence the reason the code is not working.
Inspiring
January 28, 2007
The thing you need to remember about sound in Flash is that Flash will resample the audio to a rate it supports so either 44, 22 or 11. This way, you can use the Sound Class to load your mp3s.

About your preloader though...