TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Adding two functions to one preloader?

Page: 1 Reply
Apr 8th 2005#167340 Report
Member since: Apr 5th 2005
Posts: 9
I am making a flash animation/movie that is about 1.4MB in file size, there is also music that plays along with the animation, but the MP3 file is about 2.4MB, so I called up the loadSound function (streaming) in the first frame, and toggled the Sound start function when the PLAY button was pressed. The PLAY button only appears once the preloader has loaded all the frames of the flash file, but it does not wait for the MP3 to finish loading.

If the user clicks on the PLAY button before the MP3 has finished loading, it won't play the MP3.

If the user waits a few seconds for the MP3 to finish loading, the MP3 plays normally.

Is there a way to make the preloader load and/or calculate the MP3 as well as the animation?


[CODE]// variable to hold the value of total frames in this movie
var loadAmount = _totalframes;
// loops until the frames loaded >= to frames in this movie
if (_framesloaded >= loadAmount) {
// when framesloaded then move play head to frame called 'start'
gotoAndPlay("start");
} else {
// otherwise do these calcualtions and display them on the scene
// to show how much of the movie has been loaded.
// variable to store the amount of bytes loaded so far
loaded = Math.round(getBytesLoaded());
// variable to store the total bytes of this movie
total = Math.round(getBytesTotal());
// calculate how much has been loaded and work that out as a percentage
percent = Math.round((loaded/total) * 100);
// labels to display on the preloader scene
bytesLoadedOutput = loaded;
bytesTotalOutput = total;
percentOutput = percent + "%";
// draw the progress bar
pb.pbBar._width = pb.pbHolder._width * (percent / 100);
// loop the preloader scene.
gotoAndPlay("loading");
}[/CODE]
Thanks in advance!
Highway of Life
Reply with Quote Reply
Apr 8th 2005#167343 Report
Member since: Aug 12th 2002
Posts: 1693
Not sure I totally got your problem here, but why don't you just put the song in to the same swf and let if get preloaded at the same time as the animation?



.... annoying green font btw.... :P
Reply with Quote Reply
Apr 8th 2005#167352 Report
Member since: Apr 5th 2005
Posts: 9
The song is being pre-loaded in the first frame with this function: [CODE]
//Load Streaming mp3 behavior
if(_global.Behaviors == null)_global.Behaviors = {};
if(_global.Behaviors.Sound == null)_global.Behaviors.Sound = {};
if(typeof this.createEmptyMovieClip == 'undefined'){
this._parent.createEmptyMovieClip('BS_Witness',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.Witness = new Sound(this._parent.BS_Witness);
} else {
this.createEmptyMovieClip('_Witness_',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.Witness = new Sound(this.BS_Witness);
}
_global.Behaviors.Sound.Witness.loadSound("thewitness.mp3",false);
[/CODE] But the all the frames finish loading before the song does, and IF the user presses the PLAY button before the Song has completely loaded, then the song won't play.

I'm trying to make it so that the preLoader includes the MP3 in the loading. And will only finish the load when both the SWF and MP3 have finished loading.

Hope that makes it clearer.

thanks!

BTW, How about this color? ;)

Highway
Reply with Quote Reply
Apr 8th 2005#167356 Report
Member since: Jan 17th 2005
Posts: 147
Put the mp3 in the swf file.

Or if it is just a matter of time, add a few frames to the orginal movie beofre the play button is suppose to appear
Reply with Quote Reply
Apr 9th 2005#167365 Report
Member since: Apr 5th 2005
Posts: 9
Well, putting the mp3 inside the SWF would create a needlessly large SWF file size.

And adding a few frames would be useless, because the length of pause needed would depend on connection speed.

-----------------------------------------

BUT.... I fixed the problem.

For those of you who would like to know the solution I came up with, here it is:

In the code that I posted above, I had this in there:

[CODE]_global.Behaviors.Sound.Witness.loadSound("thewitness.mp3",false);[/CODE]
I used 'false' to make the song wait to play until the user pressed the PLAY button, which I called this action for the PLAY button:
[CODE]on (release) {
// Play the sound
_global.Behaviors.Sound.Witness.start(0,1);

// Play the animation
_root.gotoAndPlay("5");
}[/CODE]

The problem, is that by changing the code above to 'false' is that it loads the sound as an event, instead of streaming. Since you can only start playing an event sound once the sound has completely loaded, sometimes the song would not play.

However, If I changed the code to 'true' to call the streaming fuction, the song would start playing prematurely before the user clicked the PLAY button.

To solve this, I added this code:
[CODE] //Load Streaming mp3 behavior
if(_global.Behaviors == null)_global.Behaviors = {};
if(_global.Behaviors.Sound == null)_global.Behaviors.Sound = {};
if(typeof this.createEmptyMovieClip == 'undefined'){
this._parent.createEmptyMovieClip('BS_Witness',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.Witness = new Sound(this._parent.BS_Witness);
} else {
this.createEmptyMovieClip('_Witness_',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.Witness = new Sound(this.BS_Witness);
}
// load the mp3
// true - streaming. false - event
_global.Behaviors.Sound.Witness.loadSound("thewitness.mp3",true);

// Stop sound behavior added
_global.Behaviors.Sound.Witness.stop();[/CODE]
This fixed the premature starting problem, and the mp3 starts playing normally when you press the PLAY button.

Now, since I have the preloader looping in frames 2 and 3 until the SWF is finished loading, I had to put the loadSound action in frame one to avoid loading the mp3 over 15 times.
Yep, it was loading over 30MB of useless mp3 everytime it loaded.

That's it, if there are any questions, feel free to ask
Thanks for all the help.
Highway of Life
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum