AS:Main - Now comes with No0b repelant
What you'll learn, hopefully
In this tutorial i'll explain about the 'Microphone' Object introduced in Flash MX2004. I'll also show some neat effects
you can use in one of your flashes as mabye a preloader, or with a little more knowledge, a full blown game.
Is it hard?
The mike object is very similar to the Camera Object
in flash. It uses some very similar properties. So if you know about the Camera object, how it works,how to apply it, then this should be a pretty simple tutorial.
How to use it!
Now onto the actual tutorial. If you ever get stuck, or are shouting 'wtf' and hitting your computer, just click on one of the links at the bottom and they should give a little
more info.
Alot of this code is taken from macromedia live docs, so if you get stuck, they are probably a good place to look.
Getting the mike!
To do anything with the mike in flash, you have to actuall find the appropriate mike and apply it to an object to do that
paste these actions in a frame in you flash. I'll explain afterwords:-
this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth());
var active_mic:Microphone = Microphone.get();
sound_mc.attachAudio(active_mic);
Now for the explaination.
1. The first line creates and empty movie clip on the timline, and calls it "sound_mc".
2. Then a new variable called active_mic is created. It is declared a Microphone object.
3. On the same line 'Microphone.get();' is used. This applies the default mike to the Mircophone Object.
4. The last line actually makes out Object usable on the stage. It applies our Object (active_mic) to our MC.
Now, try testing you movie. If you speak into the mike you should be able to hear your voice amplified coming from
your speakers.
Making it clearer!
When you tested the previous example the sound may have appeared muffled, or abit fuzzy. In this part i'll tell you how to
make the sound alot clearer and easier on the ear.
Put this code after the code you just pasted on the timline:-
active_mic.setRate(22);
active_mic.setUseEchoSuppression(true);
Explanation:-
1. The top line sets the Microphone amount of Khz per second, The higher the number(uaually) the better the quality.
2. The second line tells the miek to use echo suppresion. This reduces the amount of feedback from the speakers, making the sound clearer.
Now if you test your movie. The sound should be clearer. If you don't notice any difference, fiddle around with the mike settings by right clicking on your preview movie,
clicking settings, then going onto the mike tab.
How to see sound!
In this final part of the tutorial i'll show you lot how to make a shape's properties change by the level of activity the mike is detecting. You could make it rotate, go smaller,
get bigger, change colour, anything you want. I'm going to work on scale, it is one of the simpler open, so most people should understand it.
It basically makes the shape expand, retract depending on the level of sound detected. The more sound, the bigger the shape.
Just paste this code under your current code:-
var amount:Number =50;
onEnterFrame = function () {
shape._xscale = shape._yscale = active_mic.activityLevel+amount;
};
And then make a Movie Clip on the stage, it can be any size, shape, whatever you want. Give it the instance name 'shape'.
Now if you test the movie when you speak into the mike the shape will expand and retract. To get different effects, just shange the variable 'amount'
to a different number. You can also try using different properties to change the effect, for example:-
var amount:Number =50;
onEnterFrame = function () {
shape._xscale = shape._yscale=active_mic.activityLevel+amo
unt;
shape._rotation = active_mic.activityLevel+amount;
shape._x = active_mic.activityLevel+amount;
shape._y = active_mic.activityLevel+amount;
};
That code will make the shape move around the stage, rotate, expand and retract, all depending on the level of microphone ativity.
That conculdes the long tutorial on the flash microphone object. I hope you understood most of it, don't just copy and paste the code though, read the explanations,
They should explain most of the code. Below is an examples of the final product! If you have any questions, just post them below.
EXAMPLE
Fully Done Project!
HELPFUL LINKS
Marcomedia
Live Doc(MX 2004)
Kirupa's Tutorial
AS : Video - My other AS
1004th Post :)
