I’m building an mp3 player that finally seems like it’s coming together. Back and forth works fine now. So I tried taking it to the next level by adding those bouncing bars that you see in most music players like winamp. Problem is. I just followed a tutorial, and by themselves the bars work fine but when I try to encase them in a function that I want to execute once the music is loaded the bars only jump once and then they stay flat. Any idea what’s wrong.
stop();
// Preloader variables
var t = 0;
var l = 0;
var p = 0;
// --------------------------<load and loop sound>-------------------------- \\
this.createTextField("status_txt", this.getNextHighestDepth(), 72, 630, 100, 22);
// create a new Sound object
var my_sound:Sound = new Sound();
musictext.text = "loading";
// if the sound loads, play it; if not, trace failure loading
my_sound.onLoad = function(success:Boolean) {
if (success) {
my_sound.start();
musictext.text = "music on";
_root.preloader._visible = false;
antiShane();
} else {
status_txt.text = "Sound failed";
}
};
// load the sound
myCount = 0;
totCount = 1;
mySongs = ['song1.mp3', 'song2.mp3', 'song3.mp3'];
nextTrack = function () {
my_sound.loadSound(mySongs[myCount], false);
this.onEnterFrame = function() {
//trace(t);
//trace(p);
//trace(l);
t = my_sound.getBytesTotal();
l = my_sound.getBytesLoaded();
if ((t>0) && (t != null)) {
p = (l/t)*100;
p = int(p)+1;
preloader.gotoAndStop(p);
}
if (l == t) {
delete this.onEnterFrame;
}
};
};
/*
var songnr:Array = ['song0','song1']
my_sound.loadSound("song"+i+".mp3", true);
trace(i);
}*/
// loop the sound
my_sound.onSoundComplete = function() {
my_sound.start();
};
// --------------------------</load and loop sound>-------------------------- \\
// ------------------------------<Play Stop button function>------------------------------ \\
var playstat:String;
playstat = 'on';
control.onRelease = function() {
if (playstat != 'off') {
gotoAndStop(2);
playstat = 'off';
my_sound.stop();
musictext.text = "music off";
//trace (playstat);
} else if (playstat != 'on') {
gotoAndStop(1);
playstat = 'on';
my_sound.start();
musictext.text = "music on";
this.nextTrack();
_root.preloader._visible = true;
//trace (playstat);
trace(mySongs[myCount]);
}
};
nxt_btn.onRelease = function() {
if (myCount == totCount) {
myCount = 0
}
else {
myCount++;
}
nextTrack();
_root.preloader._visible = true;
trace(myCount);
};
prev_btn.onRelease = function() {
if (myCount == 0) {
myCount = totCount
}
else {
myCount--;
}
nextTrack();
_root.preloader._visible = true;
trace(myCount);
};
nextTrack();
// ------------------------------</Play Stop button function>------------------------------ \\
antiShane = function () {
// ----------------------------------------<Animated Bars>------------------------------------- \\
// Project: make a fake equalizer like movie clip for use when music is playing in Flash
// project has lines and toppers, each labeled linex & topperx where x is 1 to 20.
// the lines make up the tall parts of the equalizer, the toppers are just a line placeholder
// for the max value of the lines
// define initial arrays
barboty = new Array();
//holds bottom of each line's _y registration point
randheight = new Array();
//holds randomly generated height of line
toppery = new Array();
//holds _y registration point of topper
decfraction = new Array();
//holds the fraction of random height of line that will be used to decrement the line's height
numbars = 6;
//defines number of lines
maxheight = 15;
//defines max height of line
minheight = 1;
//defines min height of line
gap = 2;
//defines distance between top of line and topper
topperdrop = .075;
//defines value to decrement _y value of topper
numsteps = 7;
//defines number of steps to decrement height of line
// this function sets values for the heights of each line in the equalizer
function initbars() {
for (i=1; i<_root.numbars+1; i += 1) {
barboty* = eval("_root.line"+i)._y;
randheight* = Math.random()*maxheight;
toppery* = barboty*-randheight*-gap;
decfraction* = randheight*/(_root.numsteps);
// set initial line height and position of topper
setProperty(eval("_root.line"+i), _height, _root.randheight*+_root.minheight);
setProperty(eval("_root.topper"+i), _y, barboty*-randheight*-_root.gap-_root.minheight);
}
}
// this function will get executed at the playing frame rate of the movie, even if the movie is stopped
_root.onEnterFrame = function() {
for (j=1; j<_root.numbars+1; j += 1) {
//set height of each line for each j in numbars
setProperty(eval("_root.line"+j), _height, _root.randheight[j]);
if (_root.randheight[j]<=_root.minheight) {
// if the line height is less than the min, then:
// set line height to the min then redo the line heights etc
setProperty(eval("_root.line"+j), _height, _root.minheight);
_root.initbars();
// the entire function initbars could be placed here if you like rather than being called.
} else {
//if not too short, decrement height of lines and position of topper
_root.randheight[j] = _root.randheight[j]-_root.decfraction[j];
setProperty(eval("_root.topper"+j), _y, eval("_root.topper"+j)._y+_root.topperdrop);
}
}
};
// ----------------------------------------</Animated Bars>------------------------------------- \\
};
The bars are encased in the function ‘anitShane’ cause of an internal joke in case anyone was wondering. thx in advance.