tailieunhanh - Học Actionscript 3.0 - p 35

Visualizing Sound Data The Waveform class The first dozen or so lines of the Waveform class will be familiar to you if you’ve been reading this book linearly. Line 1 declares the class’s package path as this class is part of the learningactionscript3 code library developed throughout this book. Lines 3 through 7 import all the other classes required by this class. Line 9 declares the class and extends Sprite so it can inherit all accessible properties, methods, and events from the Sprite class. As discussed extensively in Chapter 6, this is important for things like being able to access properties like. | Visualizing Sound Data The Waveform class The first dozen or so lines of the Waveform class will be familiar to you if you ve been reading this book linearly. Line 1 declares the class s package path as this class is part of the learningactionscript3 code library developed throughout this book. Lines 3 through 7 import all the other classes required by this class. Line 9 declares the class and extends Sprite so it can inherit all accessible properties methods and events from the Sprite class. As discussed extensively in Chapter 6 this is important for things like being able to access properties like graphics use event listeners and add instances of this class to the display list. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 package import import import import import public class Waveform extends Sprite private var _bytes ByteArray new ByteArray private var _fft Boolean private var _g Graphics public function Waveform fft Boolean false _fft fft _g onVisualize false 0 true private function onVisualize evt Event void _bytes _fft plotWaveform 0x009900 50 plotWaveform 0xFF0000 100 private function plotWaveform col uint chanBaseline Number void 1 col col 0 chanBaseline for var i Number 0 i 256 i i chanBaseline 50 i chanBaseline Chapter 11 Sound 319 Download from Wow eBook Visualizing Sound Data NOTE Using two loops of 256 values rather than 1 loop of 512 values makes it easier for us to draw the left and right channels separately. For example because the loop counter i ranges from 0 to 255 we can use it as an x coordinate for each point of our waves. If we used a .