Be a Supporter!

As: External Audio Optimization

  • 1,552 Views
  • 9 Replies
New Topic Respond to this Topic
64
64
  • Member since: Feb. 16, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
As: External Audio Optimization Aug. 2nd, 2006 @ 05:41 PM Reply

AS: Main.

Sometimes Newgrounds will make paragraphs in the middle of the code, screwing it up if you wish to copy and paste. Hopefully, you can sopt if something doesn't look right.

I've kind of made a topic like this, but it didn't focus on this subject. This will show you how to load Mp3 files from the internet to play in your Flash. "Why the hell would that be of any use to me?" you ask? Here are some pro's and con's to the matter:

Pro's
Smaller SWF and FLA file size.
If your Flash takes up too much space to be on Newgrounds because of the music, it will now fit.
No need to compress, you can have perfect quality.
Great for games.

Con's
Longer loading time.
Not good for movies where you have to stream them (won't sync).
Some Actionscript knowledge required.
A host such as MyFileHut is required.
Only Mp3 files will work.

It's actually very easy. Here's an example.

For something like this, make a raw preloader (without the actionscript) which basically contains a line and a bar. The bar will mask the line, showing the progress. Name this bar, creatively, bar.

Leave that alone for right now. On the first frame of the Flash, put this:

sound = new Sound();
sound.loadSound(url, false);
isPlaying = false;

This makes it easy for loading one song in a movie. I'll get to using multiple songs later. In my example, my song was Vicinity of Obscenity, which the url was http://webzoom.freew..20Of%20Obscenity.MP3


. Easy enough, I added this to the top of those three lines:

url="http://webzoom.freewebs.com/cheatfrea
k64/Vicinity%20Of%20Obscenity.MP3"

Back to the preloader. On the movieclip, just put this code:

onClipEvent (enterFrame) {
loading = ((_root.sound.getBytesLoaded()/_root.sound
.getBytesTotal())*100);
bar._xscale = loading;
if (bar._xscale>=100 && _root.isPlaying == false) {
_root.sound.start();
_root.isPlaying = true;
}
}

It won't work unless Local Playback Security is set to Access Network Only, so set that at the bottom of the Flash publish settings.

For a game with different music for different levels, it's a bit more complicated. Let's make an example with two songs. Put this on the first frame:

url="http://www.site.com/song1.mp3"
url2="http://www.site.com/song2.mp3"
sound = new Sound();
sound.loadSound(url, false);
sound2 = new Sound();
sound2.loadSound(url2, false);

The isPlaying isn't really necessary here.

The preloader is pretty user-friendly. Before the level starts, stick one in there with a stop(); action. Use the same script as before, but change:

loading = ((_root.sound.getBytesLoaded()/_root.sound
.getBytesTotal())*100);

Change the sound part to sound2 or whatever you made it as before. Also, replace:

_root.sound.start();
_root.isPlaying = true;

with:

_parent.play();

It depends on what you're making this for, but hopefully you follow. That will cause it to play (going to the actual level) once the sound is loaded. On your level frame, put this:

_root.sound.start();

This will actually load the song once you're at the level. You can replace sound here, too.

To stop the music, the code is simple:

_root.sound.stop();

If something went wrong, here is the FLA for the example above:

http://webzoom.freew..reak64/musicdemo.fla

JamsCo
JamsCo
  • Member since: Jun. 20, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: External Audio Optimization Aug. 2nd, 2006 @ 05:49 PM Reply

Awesome work man!

64
64
  • Member since: Feb. 16, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As: External Audio Optimization Aug. 2nd, 2006 @ 06:31 PM Reply

Thanks.

64
64
  • Member since: Feb. 16, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As: External Audio Optimization Aug. 2nd, 2006 @ 11:17 PM Reply

No more comments?

Depredation
Depredation
  • Member since: Sep. 5, 2005
  • Offline.
Forum Stats
Member
Level 17
Game Developer
Response to As: External Audio Optimization Aug. 3rd, 2006 @ 09:11 AM Reply

At 8/2/06 11:17 PM, ChtFreak64 wrote: No more comments?

Its a good tutorial. But it takes a long time to load, there is a way to change the quality so there is less loading time. But i cna't remember it, XD.
Anyway, nice tutorial, pretty simple though:0

From my point of view , lol.

BBS Signature
64
64
  • Member since: Feb. 16, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As: External Audio Optimization Aug. 21st, 2006 @ 09:44 PM Reply

At 8/3/06 09:11 AM, Depredation wrote: Its a good tutorial. But it takes a long time to load, there is a way to change the quality so there is less loading time. But i cna't remember it, XD.
Anyway, nice tutorial, pretty simple though:0

From my point of view , lol.

Sorry, I've been away. Yes, there is a way to change the quality, but it doesn't have to do with Flash. Just put the sound into something like Audacity (sp?) and export it into a lower quality, and it'll load faster.

Corey
Corey
  • Member since: Aug. 3, 2004
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to As: External Audio Optimization Aug. 21st, 2006 @ 09:50 PM Reply

That's awesome man, I've always wondered how to do that. But on a lot of major websites they have flash music players which starts right when you go to the page. how is that possible?


BBS Signature
64
64
  • Member since: Feb. 16, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As: External Audio Optimization Aug. 21st, 2006 @ 10:09 PM Reply

They probably have the music inside the Flash. This loads it outside.

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to As: External Audio Optimization Oct. 30th, 2007 @ 06:59 PM Reply

The audio portal kinda works like this (save for it using as 3 so it gets the fancy visualizations).
It is quite simple, start playing the sound before it is completely loaded.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

DELUCA2400
DELUCA2400
  • Member since: May. 4, 2007
  • Offline.
Forum Stats
Member
Level 25
Blank Slate
Response to As: External Audio Optimization Oct. 30th, 2007 @ 09:21 PM Reply

Thanks Alot Man