topical media & game development
mashup-rmx-20-flashamp.ax
mashup-rmx-20-flashamp.ax
(swf
)
[ flash
]
flex
var i:Number; //counter variable
var j:Number; //counter variable
var index:Number; //playlist index
var tl = this; //main timeline reference
var alb:Number = 7860001; //initial album ID
//create the sound object
var snd:Sound = new Sound();
snd.onLoad = function(){
snd.setVolume(50);
snd.start(0,1);
}
//loads multidimensional arrays via LoadVars
String.prototype.str2array = function (char){
var spectrumValues = this.split(" ").join("").split(char);
var spectrumIndex = 0;
while (spectrumIndex < spectrumValues.length){
spectrumValues[spectrumIndex] =
spectrumValues[spectrumIndex].split(char.split(",")[0]).join("").split(char.split(",")[1]).join("").split(",");
spectrumIndex++;
} // end while
return(spectrumValues);
}
fps = 24; //the SWF's frame rate
numBands = 16; //number of EQ bands
//Zero out all the EQ bands
for (i=0; i<numBands; i++){
setProperty("tl.s" + i, _yscale, 0);
}
//LoadVars to handle the loaded spectrum
// values from FlashAmp Pro
var spectrumLV = new LoadVars();
spectrumLV.onLoad = function (success){
if (success){
sv = this.sv.str2array("],[");
return(sv);
} else {
trace("Error loading/parsing LoadVars.");
}
}
//now you're ready to load the XML
// playlist for this album
var titles:Array = new Array();
var tracks:Array = new Array();
var muzak:XML = new XML();
muzak.ignoreWhite = true;
muzak.onLoad = getTrax;
muzak.load("playlist-7860001.xml");
//this method parses the XML file, plays
// the 1st track and initiates loading of
// the spectrum values
function getTrax(){
var trax:Array = this.firstChild.childNodes;
for(i=0;i<trax.length;i++){
titles.push(trax[i].attributes.lbl);
tracks.push(trax[i].attributes.src);
}
index = 0;
snd.loadSound(tracks[0]);
file = alb + "-" + index + ".txt";
spectrumLV.load(file);
setStatus();
}
//this method updates your EQ clips
// with the current array value
function updateSV(){
sp = Math.floor(snd.position / 1000 * fps);
vol = snd.getVolume() / 100;
for (i = 0; i < numBands; i++){
setProperty("tl.s" + i, _yscale, sv[sp][i] * vol);
}
}
//this method starts the EQ animation
function setStatus(){
spectrumPos = Math.floor(snd.position / 1000 * fps);
spectrumInt = setInterval(updateSV, spectrumPos, snd);
}
//this method gets called onSoundComplete
// or during Sound.pause()
function clearStatus(){
clearInterval(spectrumInt);
}
(C) Æliens
18/6/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.