rendered paste body// ActionScript file
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.utils.*;
array indice eg., songArray[3] = "somesong.mp3";
songArray = new Array();
songArray[0] = "assets/Darude - Ecstacy.mp3";
songArray[1] = "assets/Darude - SandStorm.mp3";
_songIndex = 0;
_barArray = new Array();
private function createSpectrumBars(): void
{
for (var i: int = 0; i < _numBars; i++)
{
// this function allows you to change the the appearance of the bars
var bar: Shape = new Shape();
var dropShadow: DropShadowFilter g94fqa2- 75, 1, 30);
bar.graphics.endFill();
bar.filters = [dropShadow];
bar.y = bar.height + 130;
bar.x = 1+i * 4;
addChild(bar);
_barArray.push(bar);
// this function allows you to change the the appearance of the blue dots
var line1: Shape = new Shape();
line1.graphics.beginFill(0x66FFFF);
line1.graphics.drawRect(250, - 90, 1, 2);
line1.graphics.endFill();
line1.y = bar.height + 95;
line1.x = 1+i * 4;
addChild(line1);
_lineArray.push(line1);
}
}
private function ioErrorHandler(event: IOErrorEvent): void{
}
public function onStop():void
{
_playtime = 0;
_sc.stop();
isplaying = 1;
}
public function onPlay():void
{
if (isplaying == 0)
{
// do nothing
}
else
{
_sc = _sound.play(_playtime, 25);
isplaying = 0;
}
}
public function onPause():void
{
_playtime = _sc.position;
_sc.stop();
isplaying = 1;
}
private var textField: TextField = new TextField();
private function getInfo(event: Event): void
{
// stores the MP3 ID3 info into an array, you can add more id3 info by adding another id3Array
id3Array = new Array();
id3Array[0] = "Song: " + _sound.id3.songName + " ";
id3Array[1] = "Artist: " + _sound.id3.artist + " ";
id3Array[2] = "Album: " + _sound.id3.album + " ";
if (_sound.id3.songName != null)
{
// formats the display and appearance of the id3 array
textField.width = 190;
textField.height = 20;
textField.x = 50;
textField.y = 100;
addChild(textField);
textField.text = id3Array[_id3Index];
var format: TextFormat = new TextFormat();
format.font = "Cambria";
format.color = 0x0099CC;
format.size = 13;
textField.setTextFormat(format)
}
id3Timer.addEventListener("timer", cycleid3Array);
id3Timer.start();
}
private var id3Timer: Timer = new Timer(8000, 10);
private function cycleid3Array(event: TimerEvent): void
{
if (_id3Index != 2) // set to higher number if you use more id3 information in the arrays.
{
_id3Index++
}
else if (_id3Index != 0)
{
_id3Index = 0;
}
}
public function cyclesongArray(dir:String,cBox:ComboBox):void
{
if (dir == 'forw' && _songIndex != 1) // set to higher number if you use more mp3 files in the songArray.
{
_songIndex++;
_sc.stop();
_sound = new Sound();
_sound.load(new URLRequest(songArray[_songIndex]));
_sc = _sound.play(_playtime, 25);
_sound.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
var data:Number = _songIndex;
data++
cBox.selectedIndex = data
}else if (dir == 'rev' && _songIndex != 0)
{
_songIndex--;
_sc.stop();
_sound = new Sound();
_sound.load(new URLRequest(songArray[_songIndex]));
_sc = _sound.play(_playtime, 25);
_songIndex = 0;
var data1:Number = _songIndex;
data1++
cBox.selectedIndex = data1
}
}
public function setSong(data:Number):void
{
_songIndex = data;
_sc.stop();
_sound = new Sound();
if(songArray[_songIndex] != "")
{
_sound.load(new URLRequest(songArray[_songIndex]));
_sc = _sound.play(_playtime, 25);
_sound.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//data++
//Box.selectedIndex = data
}else{
mx.controls.Alert.show("Song doesn't exist!");
}
}
private function animateBars(event: Event): void
{
SoundMixer.computeSpectrum(_ba, true, 0);
for (var i: int = 0; i < _numBars; i++)
{
_barArray[i].scaleY = _ba.readFloat();
_lineArray[i].scaleY = _ba.readFloat();
}
}
}
}