Java Reference
In-Depth Information
}
function mouseDragged(event:MouseEvent):Void{
mouseIsDragging = true;
dragLocation = event.x;
}
}
In Listing 9-6 we can see that
SoundControl
extends
AudioVisualization
, which is a simple base class
used by this example. We will take a look at it in a moment in Listing 9-7. In the
init
function of
SoundControl
, we see that the background rectangle is added as well as the Pause/Play button. When the
button is clicked, the function
buttonClicked
is called, which updates the text of the button and tells the
soundPlayer
to either play or pause.
The seek bar is bit more interesting; it is composed of two shapes: a
Rectangle
for the long
horizontal part and a
Circle
that has its
translateX
bound to the function
calculateLocation
. This
function takes the current time and the location of any drag event. Even though both of these values are
in scope within the function
calculateLocation
, by passing them in to the function, we cause the bound
value to be updated whenever they change. Remember, binding to a function with no parameters causes
the bound value to never update.
By adding event functions to the group's
onMouseDragged
and
onMouseRelease
attributes, we can
respond when the user clicks and drags the seek bar. The function
onMouseDragged
sets
mouseIsDragging
to true and updates the value of
dragLocation
, which in turn causes the bound
translateX
attribute of
the circle to be updated. When the mouse is released, the circle goes back to the current time of the song.
Let's take a quick look the class
AudioVisualization
, since it gets used by four of our classes in this
example. Listing 9-7 shows the source code.
Listing 9-7.
AudioVisualization.fx
public class AudioVisualization extends Group{
public-init var soundPlayer:SoundPlayer;
}
In Listing 9-7 we can see that it is a very simple class;
AudioVisualization
extends
Group
and allows a
SoundPlayer
to be specified when it is created.
SoundPlayer
and all three example effects extend this
class.
Now that we have the basic framework spelled out, we can explore the details of these effects.
Bars
The first visualization we'll look at will show a number of bars, one for each level, which grow and shrink
along with the values stored in the sequence
levels
of the class
SoundPlayer
. Figure 9-3 shows our first
example visualization.