00:00
00:00
Upgrade Your Account!

Hey! To start this decade right, we believe Newgrounds should be ad-free for EVERYONE. For this to work, we need people who have the means to become paying supporters. For just $3 per month or $25 for the year, you can help this happen and get some nice perks!

For the month of January we have disabled ads on all E-M content. We need 182 people to reach our January goal of 3,000 active supporters. If we hit that, we'll continue with a new goal in February!

Please check out our Supporter Upgrade and consider coming aboard!

AS: Sound Stream

1,408 Views | 1 Reply
New Topic Respond to this Topic

AS: Sound Stream 2010-11-07 18:31:20


Welcome to the AS: Sound Stream tutorial, here you will learn how code audio streaming on Flash.
===================
AS: Tutorials Center
===================
Sorry if you noticed any grammar typos, not my mother language :(
===================
First of all, why stream sounds? Because many submissions suffer from giant file size not only because intensive graphics and heavy programming but because the sound. Generally on the high quality submissions, the author prefers to put on the imported sound properties, raw 44hz which actually fills up a lot to the file size (or putting up on 160kbps with best quality on MP3). Taking as exampe, Punk-O-Matic 2 from Evil-Dog could have saved a lot from file size only by streaming the songs. Another good reason from stream songs is because you actually DON'T need to download any sound.
====================
Streaming songs already did people create enterteining submissions as:

=====================
Ok, so how we are going to do this?

When you press the download button to any Audio Portal song, you will see the download screen will show the site which the song was hosted, the ID integer, file, etc...

To we begin to script the streaming is important you take knowledge that the hosted ID will be the key to we produce this.

Also, we can do it over 2 ways, one is begin to stream the sound when you want to it play, like during a keyframe event and the other is you type the ID integer on a input box text field and press a button to load it.

FIRST WAY:
Let's begin by creating a variable to stream the song you want, before it, go on the audio page from the submission you want to the song play and you will see that on his link he will have an ID value.
http://www.newgrounds.com/audio/download /#
* # = ID
As I said before, this will be our key.
Doing the variable: You can call it whatever you want but just put it according during your scripting, I'll do ID (creativity #1 :P).

So simple type:
_root.ID = "http://www.newgrounds.com/audio/downloa d/#";
// # = your ID number.

Now to do this play, we need to create a sound object variable to do it grab the sound, load and play:
_root.mySound = new Sound();
// in my case, the name I choosed was 'mySound'
_root.mySound.loadSound(_root.ID,true);
// by typing the true check, you will be setting your sound to stream it

Now hit CTRL + Enter to test your movie and you will see that the sound actually plays!! <:D
*Wait some secs., he can't play at the exact milisecond you pressed, think on him like the loading bar which have on each audio portal submission.*

Let's proceed....

SECOND WAY:
The second way will be with a button which will load and play your sound, basically do your button (or you can take one from the Components or Common Libraries) and put it on your stage. Now, open an input text field on your stage and give it INSTANCE NAME from 'IDbox' Ok, check if you have a button and an INPUT text field with the correct instances and now take your selection tool and give a single click at your button and hit f9 to we begin the programming. Type:

on(press)
{
     _root.ID = "http://www.newgrounds.com/audio/download/"+_root.IDbox.text;
     _root.mySound = new Sound(); 
     _root.mySound.loadSound(_root.ID,true);
}

So what I did is almost the same from the other but now without the ID (but with the ID at the same time). The variable 'ID' will load the value from the IDbox input text field you did and the sound object 'mySound' will stream the variable.

But I'm sure you will want to load other IDs, so to don't play a sound over another, let's do it shut the other sound.

Simple add after the pressing function:

stopAllSounds();

Hit CTRL + Enter and give a test, remember to wait some sec. before press the button and the sound will play <8D and if you publish it and upload to NG Dump you can see that the file will be much more small than if it had a sound.

Now we can give a play at our sounds, if you want your sound to loop when it ends, do:

_root.mySound.onSoundComplete = function()
{ 
        _root.mySound.start(0,999);
};

So when the sound finish he will loop and will play again 999 times (this system works exactly as when you put a sound to your timeline and set how many times to repeat but dynamically).

If you want to the song you're streaming have a different volume do:

_root.mySound.setVolume(#);

* #= Sound volume integer

============
Randomizing ID integer to load/play:
If you want to when you press something randomize the integer on your input text field, simple add:

_root.IDbox.text = random(#);

* #= integer

I would probaly do it to randomize by 350000 (because it is ± the total from sounds that we currently have here on the AP).

FURTHER NOTES:
* On this tutorial you learned some functions from sounds and events you can do
* Setting sound volume
* Stream sounds
* Sound properties
* Lowering your file size
* Randomize
* You can also find out the user who did the song by studying the Newgrounds Source Code (go on a page from the NG database and give a right click>source code).
* You can study additional features as: (more advanced)
id3.album
id3.artist
id3.genere
id3.comment
* You can also trace the bytes loaded from your sound (in case of download).
* You also learned that my mother language isn't english :P

I hope you learned everything necessary to stream your songs, if you have any question please leave your question here.

Response to AS: Sound Stream 2010-11-08 16:45:03


At 11/8/10 03:17 PM, xKiRiLLx wrote: Okay, this would be helpful for a beginner, but... why AS2?

Don't you think that was a really great thing EON and me create radio engines entire on AS2? Also, EON did "Newgrounds in a box", the game engine was entire done in AS2, open the game and drop your mouth on the ground. Plus, AS3 is just good to people who prefer to work with other languages because AS3 is more to the OOP side. You can do it with AS3 too. :)