PHOBOSLAB

Blog Home

Flash Music Visualization Engine

Better late than never… As I promised earlier, I uploaded the complete Flash and ActionScript source for Venetianization. It is, potentially, a framework for simple yet very powerful and accurate music visualization movies. Effects can be programmed for a set of elements and issued at nearly exact points in time. The complete source (Flash CS3, ActionScript 3) can be downloaded here: venetianization.zip

A few word about the inner workings of this: As you saw in my demo project, you work on an 2D array of circles. You basically animate these circles through 3 layers of definitions:

All these definitions can be found in the Script.as beginning on line 47. Selections are specified from the base selection (none) and then chained through several methods. Most selections in my script are calculated on load if possible. However most computers have plenty of processing power to calculate a few complex selections for each frame dynamically. So don’t worry too much about this. All coordinates for the selection are specified in a normalized format (from (0,0) to (1,1)).

A selection could look like this:

parent.cache.myFancySelection = parent.base
    .rect( 0.4, 0.4, 0.6, 0.6 ).fill( 0.5, 0.5 )
    .circle( 0.2, 0.2, 0.2 ).fill( 0.2, 0.2 );

This creates a selection with the filled rectangle from (0.4, 0.4) to (0.6, 06) and the filled circle centered at (0.2, 0.2). All methods to modify selections can be found in Selection.as.

To define an action, we add a function to the script object:

this.script.myFancyAction = function( parent:Field, time:Number, age:Number ) {
    parent.cache.myFancySelection
        .each( parent.fx.plasma, {}, time/1000 )
        .each( parent.fx.scale, { factor: (1-age)*3 }, time );
}

This action takes our previously created selection and issues two effects on all selected circles. The age parameter tells us the how old the action is. It starts at 0 and dies at 1. To define when an action starts and when it ends, we have to put it in the queue:

this.queue = [
    { start: 1000, end: 3000, func: this.script.myFancyAction },
    { start: 4000, end: 6000, func: this.script.myFancyAction },
    { start: 7000, end: 9000, func: this.script.myFancyAction },
];

This will issue our action 3 times (at millisecond 1000, 4000 and 7000) with a duration of 2000 milliseconds each. So what we get from all of this, is a rectangle and a circle, whose elements will scale according to a plasma effect and their age.

Thats it in a nutshell. Be warned, some things were not really thought through or changed during the development of my project. For instance the Effects class does far less than I at first thought it would. You could extend this to transform elements, add a blur filter or the like. If there’s really interest in all this, I could write a more complete documentation. Just leave a comment and let me know.

Oh, and if you just want to see how a simple Flash Movie can use 100% of your CPU, just change the size of the Field and recompile (Field.as line 15).

Monday, January 7th 2008
— Dominic Szablewski, @phoboslab

13 Comments:

#1 – B – Wednesday, May 7th 2008, 23:43

the .fla file doesnt work!
unexpected file format

#2Dominic – Monday, May 12th 2008, 00:57

It's Flash CS3. Older Flash versions won't load it.

#3 – TheCrusher – Tuesday, May 13th 2008, 01:56

I'm just wondering of how to get my own song in there :)

#4Nobula – Monday, May 19th 2008, 20:44

I'm realtively new to Flash/Actionscript so this may be very silly to ask....

How do you call/include your external scripts? I can't see any connection between your 'Play' button and how everything launches.

#5Nobula – Monday, May 19th 2008, 20:52

Elaborated:

How are the .as scripts included when I compile the FLA? I can't seem to find any calls or links anywhere (as I said, this is all rather new to me)

#6Dominic – Saturday, May 24th 2008, 14:48

@TheCrusher: Just delete the original MP3 from the library, throw in your new one and in properties->linkage set the Class to "Soundtrack".

@Nobula: You can set the "Document class" in the properties for the Stage. This is also the name of the first .as file to be included.

#7MOin – Wednesday, September 24th 2008, 20:58

Thanks a lot dominic i learned a new thing today, i'll put it to test someday however i downloaded the file and thanks for providing such nice service. whats better than a source file to understand it properly.

#8 – Liam – Saturday, September 27th 2008, 23:12

Hi, I'm having problems putting in my own track. The visualization is still the old track. Can you help! Thanks

#9Dominic – Monday, September 29th 2008, 09:32

The animation is hand-crafted. It will not magically adept itself to the music. Look at Script.as for the definition of the animation. You can use an audio tool like GoldWave to set and export markers to find the timing of various events.

#10 – Jammer – Friday, January 23rd 2009, 03:39

looks cool how did you calculate all the sound hits? i.e. when the bass kicks in and the number of circles increases and pulsate quicker....

#11Dominic – Sunday, January 25th 2009, 21:04

Most of these points where set by hand in GoldWave - i.e. playing the music, hitting the "Set CUE point" shortcut in rhythm and then exporting a .cue sheet :)

#12 – Someguy – Friday, January 20th 2012, 23:13

This doesn't seem to really be a framework persay. What it looks like is really a "way of putting together some code"

#13 – wak – Saturday, February 8th 2014, 20:28

Lame