PDA

View Full Version : Audio file preloader won't work


phil_roy
07-09-2005, 12:24 PM
I recently looked at http://www.kennybellew.com/tutorial to create a preloader that loads an MP3 in the first frame of my main timeline. The tutorial told me to create a movie clip and place it on the first frame of the timeline. Inside that clip, I have the following code...
onClipEvent(load) {
_root.stop();
myMusic = new Sound();
myMusic.loadSound("loop.mp3", false);
_root.loadBar._xscale=0;
myMusic.onLoad = function() {
myMusic.start(myMusic, 999);

// this code added by phil
firstSoundVolume=80;
_root.myMusic.setVolume(firstSoundVolume);
var soundtog = 1;
var talking = 0;
//
}
}

onClipEvent(enterFrame) {
mySoundBytesTotal = myMusic.getBytesTotal();
mySoundBytesLoaded= myMusic.getBytesLoaded();
mySoundLoading=Math.round((mySoundBytesLoaded/mySoundBytesTotal)*100);
//
if (mySoundLoading<100) {
_root.loadBar._xscale=mySoundLoading;
}
else{
myMusic.stop();
_root.gotoAndPlay(2);
}
//
}

I just need the fuel gauge to get to 100% and then for the total project to proceed playing. But I can't get it to work. I can get the sound to load and keep looping (but the timeline never moves) if I leave out the goto near the end....or I can get the timeline to continue, but the sound gets killed of once out of the first frame.

I have another preloader in the first frame of the main timeline also. However this one monitors the graphics being loaded and has no stop or start commands. This is because there are few graphics and it loads quickly....but I then need the sound to load and then the main timeline to start playing.

Phil

creynders
07-09-2005, 12:37 PM
The movieclip in which the sound is loaded, should be present for as long as you want the sound to play. So if you want it to loop forever, the movieclip should span all frames of your main timeline.

phil_roy
07-09-2005, 11:20 PM
EDITED BY PHIL (Have managed to solve some things)

OK, that's certainly helped me a lot....but one thing to ask and iron out.

The sound is a loop and I want it to play through the timeline (you've indicated how to do that to start with across the main timeline) but also across all scenes. So do I just make an instance of the movie clip in each timeline? Will that possibly cause the sound to repeat over itself?

Many thanks,

Phil

oldnewbie
07-10-2005, 03:57 AM
For the music to loop across scenes, you have to use a soundObject...

http://www.kennybellew.com/tutorial/

Or load it as an external sound.swf on another level, as we used to do it before soundObjects...

http://www.flashkit.com/tutorials/Audio/Playing_-BJ_Mace_-71/index.php

phil_roy
07-10-2005, 04:46 AM
Well this is more or less where I came in. As I mentioned at the beggning, I've looked at the kennybelllwe stuff...in fact, I've even paid for the files that are avialable.

But if you look at the bottom of this page....
http://www.kennybellew.com/tutorial/dynamic_preloader.htm
It's exactly where I got stuck. Down the bottom for an automatic preloader, it says you should place a movie clip on the stage. This is where I'm getting stuck.

With regards the second link, I can't see anything in there about a preloader.

What I am wanting is for a preloader to load an external loop.mp3 before continuing on...and that this loop will play continuously across multiple scenes.

Sorry, but I went back to those pages but they either show a) how to get a sound to play continuously without mention on a preloader or b) show a preloader with no discussion of multiple scenes.

Phil

phil_roy
07-10-2005, 09:38 AM
Or load it as an external sound.swf on another level, as we used to do it before soundObjects...

http://www.flashkit.com/tutorials/Audio/Playing_-BJ_Mace_-71/index.phpOK, I've gone back to the beginning and taken this tutorial you mention on board and I seem to have it working OK.

I've also managed to do a couple of things with the "loop.swf"....put its own preloader in the first frame, so that the loop music preloads before playing in its own swf....and added a button to switch the sound on and off.

A couple of questions though.

1. Back on the main timeline, I now haveloadMovieNum("loop.swf",1);as the code. But how do I stop the main timeline from continuing on until the swf audio has fully loaded? Or, said a different way, how do I get the preloader I want to put in the main timeline also, to factor in the size of the loop.swf file?

2. Later on in a scene, an FLV movie plays of someone talking. When it does, I want the volume of the loop.swf to drop down to 15% volume. Not all sound, but just the sound in the loop.swf file. How do I do that?

Thanks,

Phil

mambenanje
07-10-2005, 10:11 AM
remember you can use target levels eg to get the sound you can write
_level1.soundObject// where sound object will be sound itself loaded into the movie


so try to use the targeting and get all the states you want. main timeline is _level0. so you can get to it from level1. give it a trial. if you have no idea of all this check the help files for this topics

phil_roy
07-10-2005, 11:05 AM
I'm still a bit lost, as I don't have an instance of anything to target do I? Based on the Flaskit tutorial, I now have a file "loop.swf" that gets loaded by loadMovieNum("loop.swf",1);(should that be "loadMovie"?) and contains a link to an mp3 ("loop.mp3")....how do I say target loop.swf -- > loop.mp3?

To target something, wouldn't I have to create a movieclip that contained the swf that I loaded or a sound object?...when what I've done is gone right away from those.

Also, this still doesn't solve the second part of the problem....not wanting the main timeline to move at all until the sound swf has fully loaded.

Phil

mambenanje
07-10-2005, 11:56 AM
well what I mean is in the the loop.swf create an instance of a sound object which u can target in the level where loop.swf will be loaded, and from there u can easily target the sound in that level, and also it will play for all scenes since it is in another level ( _level1)

phil_roy
07-12-2005, 11:27 AM
Sorry, I'm just going round in circles. I am trying what you suggest but it just seems to create more issues.

OK..here's where I'm at. I have a file loop.fla, and in that there are 3 frames. Frame 1 is a preloader component, as I want the sound to preload with a fuel gauge. For frame 2, I've imported an mp3 to the library, set its linkage to the Export for actionscript and export in first frame with an ID "loop_music". I also have a "turn sound off" button on this frame that simply goes to the next frame. But anyway, my code for this 2nd frame isstop();
loopMusic=new Sound();
loopMusic.attachSound("loop_music");
loopMusic.start(loopMusic, 999);On the 3rd frame I have the scriptstopAllSounds();and a button to turn the sound back on again, by going to frame 2.

By itself, this swf works fine...the music loads, the on/off button mutes the sound...but now, since making the sound object, the swf no longer produces sound when loaded into the main swf.

So....looking at the main fla...on frame 1 on one layer, I have that preloader again, to indicate the loading of graphics....please ignore this for a while, as it's another issue (getting the sound and graphics preloaders to work together).

On the same frame 1 on another layer, I simply haveloadMovieNum("loop.swf", 1); The loop.swf is loading, but now since addiing the sound object in the loop.swf, the sound doesn't play in this timeline of the main swf (remembering I need the loop to play across multiple scenes) and can't seem to tell the sound in level1 to start playing or set its volume.

Phil

cancerinform
07-12-2005, 01:26 PM
Oldnewbie is going to insult me soon because he doesn't like components :eek: but here is a soundpreloader component, which lets you go to another frame. However, one problem may be that you have 2 preloaders simultanously which may interfere each other.

http://www.flashscript.biz/components.html#Preloaders

phil_roy
07-12-2005, 07:34 PM
I appreciate the link, but if I use that approach, I go back to the problem of having a loop that won't play across scenes. All advice so far has been to have the sound in a separate swf so that the sound can repeat across multiple scenes.

Phil

cancerinform
07-12-2005, 08:50 PM
Wrong! Give the first frame in your scene a unique name and place that as framename, which you should do anyways. And if you read the flash help files you should avoid using scenes and use movieclips or new movies. I have seen movies with many scenes and it was a disaster working with them apart from the filesize.

cancerinform
07-12-2005, 09:52 PM
Whoops, I guess i misunderstood, too much work recently. :confused: Sorry for that, but one thing is true you can see that by using scenes you run into problems. Make separate movies or movieclips out of that. Then your problem may be also solved + you get a movie you can easily modify and work with.

Flash help files:
http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00000809.html