UPDATE (01-18-2009): Some of you may have noticed that the Flash SWF was missing if you were viewing this post via its permalink. It’s fixed now. Sorry ’bout my screw-up.
UPDATE #2 (08-23-2009): Just realized that the text file with the sample ActionScript class was called “BasicAnalysis.txt”. It should’ve been called “BasicAnalyzer.txt”, which you’d need to rename to “BasicAnalyzer.as”. The link has been updated below.
Most of my traffic comes from searches for Actionscript 3 spectrum analysis. Because of this, I decided to post an updated example that you can use to conquer your SoundMixer.computeSpectrum() woes. I realized that my original post had source code that wasn’t entirely transparent — and thus, probably not as useful as it could be.
This new example shows how you can draw a series of columns (using basic Graphics.drawRect() code) and how you can do something a little more interesting. I wanted to include both so that people learning from this code don’t get too confused.
Download the source: BasicAnalyzer.txt (you’ll want to rename the extension to .as).
Things you might gain from referencing this class:
SoundMixer.computeSpectrum() writes toThe source is fully commented, so feel free to snag it for your own use.
You can either make this class your FLA’s document class if you want to try it out, or you can add it as a child of any DisplayObject. Though, there’s some positioning based on stage.stageHeight in there, so your mileage may vary. If you do make it your document class, the Flash movie you’re seeing is 560px by 400px.
Also if you’re interested, the music is “Venus Morning” off an album called “Talk Strange: A Beat Tape Inspired by Bjork” by Dert. Click on his name for the download. Highly recommended.
UPDATE #3 I created a ZIP file with the code and an FLA demonstrating how to use it. You can grab that package here: BasicAnalyzer.zip. It was created using Flash CS4, but should be able to be opened using Flash CS3.
14 Responses to Another computeSpectrum() Example
on January 23rd, 2009 at 12:01 pm
ouaaaaaaaa what is it the song ?
i’m french your player is very good
on January 23rd, 2009 at 4:22 pm
gaien, the song is listed at the bottom of the post: “Venus Morning” by Dert. You can download the album here .
on January 25th, 2009 at 2:13 pm
Ha thanks you very mutch siorry for my english is very low and poor.
i dont see in the txt by writted you but thx thx thx ^^ what not inset a flash player in you flash spectrum ? for play the next track no is good idea no ?
on February 11th, 2009 at 11:17 pm
I don’t see anything
on February 16th, 2009 at 12:25 pm
this is great, thank you very much for the source.
cheers
on March 30th, 2009 at 9:14 am
awesome
on May 27th, 2009 at 11:34 pm
good job. Like the song and great example.
on June 4th, 2009 at 1:25 am
I’ve used FLEX 3.0 Pro and AS 3.0 on and off over the last year but I’ve been sick on and off also and not as involved as I’d like to have been.
Can you give some simple explicit steps to what you mean by making your class a child of a stage object in Flash CS3?
I have a horizontally animated oscilloscope animation that’s of sort of a random nature. What I’d like to do is take what your using for the vertical equalizer, mirror them across a horizontal center line, and use them as masks to show only that part of the oscilloscope animation that is relevant.
Obviously the bars above and below the centerline I’m having an alpha fade so it’s not just a cut off of the underlying animation, but I cannot even get past the “packages cannot be nested” or importing. That’s what I mean by AS 3.0 involvement.
I’ve been busy getting my health back and doing projects in AS 2.0
Thanks - great stuff (the music too).
on June 7th, 2009 at 11:21 am
I’m doing a simple use of making the action script file the documents class file but getting this very odd error,
intrinsic class flash.display.BitmapData
on June 7th, 2009 at 11:38 am
@bob:
Regarding some of the questions you have regarding “making your class a child of a stage object in Flash CS3″: the source code I attached to this blog post is just a Sprite — one of the core DisplayObject classes in ActionScript 3. I’d highly recommend getting acquainted with this new shift in thinking since you’re coming from an ActionScript 2 background. Adobe has a good intro article here:
http://www.adobe.com/devnet/flash/quickstart/display_list_programming_as3/
If you’re not familiar with this aspect of AS3 yet, then my guess is that your experience with Flex Builder 3 revolves more around MXML components, which is definitely different.
If you want to try compiling this example in Flash CS3 (or CS4), you can follow these steps:
1. Create a new FLA file (ActionScript 3.0) and save it somewhere on your hard drive.
2. Grab an mp3 file from your music collection and put it in the same folder as your FLA. Rename the file to
example.mp3.3. Download my source code and rename the file from
BasicAnalysis.txttoBasicAnalyzer.as. Put that file in the same folder as the FLA you created. Don’t put it in a subdirectory. It’s needs to be right next to your FLA.4. Back to the FLA in Flash. Click on the first frame on the root timeline, and open up the Actions panel.
5. Input the following code in the Actions panel:
6. Test the movie (Command / Control + Enter) and the example should work.
Now regarding the BitmapData error you’re getting — I really have no clue about that. The example source code doesn’t use the BitmapData class anywhere in it, so I don’t know why it’s trying to reference it.
on August 10th, 2009 at 6:10 pm
Mike, I’ve been real busy with other things, but I wanted to get back to this. I’m familiar with the ActionScript 3.0 programming model in FLEX pretty well and have been involved in the GUMBO beta test. MXML is something I mastered when FLEX first came out.
I do agree though, that I want to get this working in my Flash CS3 for Mac OS X 10.5.7 (I’ve not been able to afford as of yet the $899 to upgrade my Master Suite to CS4).
Anyway, I’ve performed the actions above periodically once in a while and it’s always the same thing, I get this error for the CS3 created ActionScript 3.0 flash file, with BasicAnalysis.as in the same directory and an example.mp3 also in the same directory with the example.swf (I’ve tried different .fla names, doesn’t seem to make a difference)….this is the error,
1 var myAnalyzer : BasicAnalyzer = new BasicAnalyzer();
2 addChild(myAnalyzer);
For Line 1 above (which obviously is not in the code itself) I get 2 errors from the BasicAnalysis.txt file,
Error #1 Description:
1046: Type was not found or was not a compile-time constant: BasicAnalyzer.
Error #1 Source:
var myAnalyzer : BasicAnalyzer = new BasicAnalyzer();
Error #2 Description:
1180: Call to a possibly undefined method BasicAnalyzer.
Error #2 Source:
var myAnalyzer : BasicAnalyzer = new BasicAnalyzer();
I also downloaded just tonight a fresh copy of your BasicAnalyzer.txt which of course I renamed as BasicAnalyzer.as
Thanks for any help.
on August 10th, 2009 at 10:21 pm
@Rt
Are you sure the BasicAnalyzer.as file is in the same folder as the FLA you created? It doesn’t matter if you’re using Flash CS3 or Flash CS4.
on August 23rd, 2009 at 1:14 am
Yes, it is in the same folder. Always has been. I’m using Flash CS3 on Mac OS X 10.5.7
Not sure if that matters or not.
I keep thinking that when a reply is published I’ll get a notification, Btw, that’s why there’s so much time between responses.
I’ll check back more often. I love your example, but it still doesn’t work for me.
on August 23rd, 2009 at 5:33 pm
@Rt
I just created a ZIP file with an FLA, sample MP3, and the BasicAnalyzer.as file. It was created using Flash CS4, but I saved it as a Flash CS3 FLA so you should be able to open it.
You can download it here: BasicAnalyzer.zip.