O'Reilly logo

Learning ActionScript 3.0 by Zevan Rosser, Rich Shupe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Waveform Visualization

Having visualized raw sound data during playback as a representation of a simple set of left and right peak meters, and then moved on to draw a graph of amplitudes of microphone input, let's combine those ideas and draw waveforms of a sound playing in real time. Figure 11-6 shows a screenshot of soundVis.fla in action, using the code we're about to explain. It depicts the left stereo channel in green and the right stereo channel in orange, with load and playback progress bars in the lower-left corner, and play, pause, and stop buttons in the lower-right corner.

A visualization of left and right channel waveforms

Figure 11-6. A visualization of left and right channel waveforms

This exercise is composed of three classes: a main document class that is responsible for playback, another class responsible for the buttons, and a third class responsible for the visualization.

The SoundPlayBasic Class

The first part of this system is a class that controls the playback of the sound. Lines 1 through 25 are the standard opening lines for packages, beginning with Line 1, which defines the package itself. Lines 3 through 12 import the needed classes, including two custom classes in lines 11 and 12: the class responsible for the visualization of the sound data, and a class defined in Chapter 8 for drawing code-only buttons.

1 package { 2 3 import flash.display.Sprite; 4 import flash.display.Graphics; 5 import flash.geom.Point; 6 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required