# Counter of tracks

**URL:** https://forum.kirupa.com/t/counter-of-tracks/351916
**Category:** flash
**Created:** [October 8, 2014, 7:31pm UTC](https://forum.kirupa.com/t/counter-of-tracks/351916 "2014-10-08T19:31:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![abmed](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@abmed](https://forum.kirupa.com/u/abmed)
#### Post date: [October 8, 2014, 7:31pm UTC](https://forum.kirupa.com/t/counter-of-tracks/351916/1 "2014-10-08T19:31:59Z")

</div>

I want to add a counter of songs in as2.  
How and where to create a text field.  
And in what line I put the script.  
I created a text field in movieClip “top” width instance name “count\_txt”,  
and tried the script: //count\_txt.text = (current\_song + 1) + “of” + song\_total;  
but it did not work.  
Help me please.  
//--------------------------------------------------------------------------  
\_root.playlist == undefined ? playlist = “mp3player.xml” : playlist=\_root.playlist;

//--------------------------------------------------------------------------  
// below here it’s all code and code …  
//--------------------------------------------------------------------------

// stage variables  
Stage.showMenu = false;  
Stage.scaleMode = “noScale”;  
stop();

// player variables  
volume = 90;  
current\_song = 1;  
top.equalizer.\_visible=0;

// playlist loading  
data\_xml = new XML();  
data\_xml.ignoreWhite = true;  
data\_xml.onLoad = loadData;  
data\_xml.load(playlist);

// parsing all xml data into flash  
function loadData(success) {  
if (success) {  
// showdisplay and playlist toggles  
showDisplay = this.firstChild.attributes.showDisplay;  
if (showDisplay == “yes”) {  
top.easeY(toppos);  
topup = false;  
display\_btn.\_rotation+=180; }  
showPlaylist = this.firstChild.attributes.showPlaylist;  
if (showPlaylist == “yes”) {  
bot.easeY(botpos);  
botup = false;  
list\_btn.\_rotation+=180; }  
// getting all titles and filenames  
aPath = new Array();  
songTitel = new Array();  
audioTracks = new Array();  
audioTracks.shuffle();  
audioTracks = this.firstChild.childNodes;  
song\_total = audioTracks.length;  
for (var i = 0; i\<song\_total; i++) {  
aPath.push(audioTracks\*.attributes.path);  
songTitel.push(audioTracks\*.attributes.title);  
// buiding playlist buttons  
bot.playlist.btn.duplicateMovieClip(“btn”+i, i);  
bot.playlist[“btn”+i].\_y = bot.playlist.btn.\_y+i_int(bot.playlist.btn.\_height) +i;  
bot.playlist[“btn”+i].txt = checkDigits(i+1)+". "+songTitel_;  
bot.playlist[“btn”+i].hit.onPress = function() {  
listClick(this.\_parent.getDepth()+1); };  
}  
//checking autostart mode  
autoStart = this.firstChild.attributes.autoStart;  
if (autoStart == “yes”) {  
playSong();  
play\_btn.\_visible = 0;  
} else if (autoStart == “no”) {  
play\_btn.\_visible = 1;  
pause\_btn.\_visible = 0;  
} else if (autoStart == “random”) {  
current\_song = random(song\_total)+1;  
playSong();  
play\_btn.\_visible = 0;  
} else {  
current\_song = int(this.firstChild.attributes.autoStart);  
playSong();  
play\_btn.\_visible = 0; } }  
// done ! all loaded succesfully. purging trash  
delete audioTracks;  
delete data\_xml;}

// list button  
function listClick(prm) {  
delete pausepos;  
current\_song = prm;  
MySound.stop();  
playSong(); }

// list scroller  
bot.list\_bg.onEnterFrame = function() {  
if (hitTest( \_root.\_xmouse, \_root.\_ymouse, true) && this.\_parent.playlist.\_height \> this.\_height ) {  
ymin = this.\_y+this.\_height - this.\_parent.playlist.\_height;  
ymax = this.\_y+3;  
conv = (this.\_ymouse -15)_1.3/this.\_height;  
conv \> 1 ? conv = 1 : null;  
conv \< 0 ? conv = 0 : null;  
this.\_parent.playlist.easeY (ymax - conv_(ymax-ymin)); } };  
bot.playlist.setMask(bot.list\_bg);

// play function  
function playSong() {  
AudioPath = aPath[current\_song-1];  
// checking for pause \> start from there  
if (pausePos\>0) {  
top.equalizer.\_visible = 1;  
MySound.start(pausePos, 0);  
pausePos = 0;  
// startup new sound  
} else {  
MySound = new Sound();  
MySound.setVolume(volume);  
MySound.loadSound(AudioPath, true);  
MySound.onSoundComplete = function() {  
top.equalizer.\_visible = 0;  
if (autoStart == “random”) {  
current\_song = random(song\_total)+1;  
} else {  
current\_song == song\_total ? current\_song = 1 : current\_song++;  
}  
playSong(); };  
// check loading bar  
top.track\_load.onEnterFrame = function() {  
total = this.\_parent.\_parent.MySound.getBytesTotal();  
geladen = this.\_parent.\_parent.MySound.getBytesLoaded();  
if (geladen != total) {  
this.\_parent.load\_display = Math.round((geladen_100/total))+"% Loaded";  
this.\_xscale = Math.round((geladen_100/total));  
} else {  
this.\_xscale = 100;  
top.equalizer.\_visible = 1;  
delete this.onEnterFrame;  
delete this.\_parent.load\_display; } }; }  
// switch paly/pause buttons  
play\_btn.\_visible = 0;  
pause\_btn.\_visible = 1; }

// play button  
play\_btn.onRelease = function() {  
playSong(); };

// pause button  
pause\_btn.onRelease = function() {  
this.\_visible = 0;  
play\_btn.\_visible = 1;  
pausePos = MySound.position/1000;  
MySound.stop();  
top.equalizer.\_visible=0; };

// next button  
next\_btn.onRelease = function() {  
delete pausepos;  
current\_song == song\_total ? current\_song = 1: current\_song++;  
MySound.stop();  
playSong(); };

// previous button  
prev\_btn.onRelease = function() {  
delete pausepos;  
current\_song == 1 ? current\_song = song\_total: current\_song–;  
MySound.stop();  
playSong(); };

// display toggle button  
top.setMask(top\_mask);  
toppos = top.\_y;  
top.\_y = int(toppos + top\_mask.\_height - 29);  
topup = true;

display\_btn.onPress = function() {  
if(topup == true) {  
top.easeY(toppos);  
topup = false; }  
else {  
top.easeY(int(toppos + top\_mask.\_height -27));  
topup = true; }  
this.\_rotation += 180; };

// playlist toggle button

bot.setMask(bot\_mask);  
botpos = bot.\_y;  
bot.\_y = botpos - bot.list\_bg.\_height -6;  
botup = true;

list\_btn.onPress = function() {  
if(botup == true) {  
bot.easeY(botpos);  
botup = false; }  
else {  
bot.easeY(botpos - bot.list\_bg.\_height -6);  
botup = true; }  
this.\_rotation += 180; };

// drag button functionality  
drag\_btn.onPress = function() {  
startDrag(this.\_parent); };  
drag\_btn.onRelease = drag\_btn.onReleaseOutside=function () {  
stopDrag(); };

// copyright button  
copy.onPress = function() {  
getURL(“[http://www.jeroenwijering.com/?item=Flash+Mp3+Player","\_blank](http://www.jeroenwijering.com/?item=Flash+Mp3+Player%22,%22_blank)”); }

// updating time display  
this.onEnterFrame = function() {  
dur = int(MySound.duration/1000);  
pos = int(MySound.position/1000);  
playTime = {};  
playTime.minutes = int((pos)/60);  
playTime.seconds = int((pos)%60);  
playTime.total = checkDigits(playTime.minutes)+":"+checkDigits(playTime.seconds);  
trackTime = {};  
trackTime.minutes = int(dur/60);  
trackTime.seconds = int(dur%60);  
trackTime.total = checkDigits(trackTime.minutes)+":"+checkDigits(trackTime.seconds);  
if (top.load\_display == undefined) {  
top.display = playTime.total+" / "+trackTime.total;  
} else {  
top.display = top.load\_display; }  
if (top.trackDrag != true) {  
prozent = pos\*100/dur;  
top.track\_play.\_xscale = prozent; } };

// prefixing a 0 to the time  
function checkDigits(toCheck) {  
return (toCheck\<10) ? toCheck=“0”+toCheck : toCheck; }

// track progress slider functions  
top.track\_back.onPress = function() {  
this.\_parent.trackDrag = true;  
this.\_parent.track\_play.onEnterFrame = function() {  
perc = (this.\_parent.\_xmouse-this.\_parent.track\_back.\_x)/this.\_parent.track\_back.\_width;  
max = this.\_parent.track\_load.\_width/this.\_parent.track\_back.\_width;  
perc \> max ? perc = max: null;  
perc \< 0.01 ? perc = 0.01: null;  
this.\_width = this.\_parent.track\_back.\_width_perc;  
this.\_parent.\_parent.pausePos = (perc_this.\_parent.\_parent.MySound.duration/1000); }; };  
top.track\_back.onRelease = top.track\_back.onReleaseOutside = function () {  
delete this.\_parent.track\_play.onEnterFrame;  
this.\_parent.trackDrag = false;  
MySound.stop();  
playSong(); };

// volume slider functions  
vol\_back.onPress = function() {  
vol\_front.onEnterFrame = function() {  
perc = (\_xmouse-vol\_back.\_x)/vol\_back.\_width;  
perc \> 0.95 ? perc = 1: null;  
perc \< 0.05 ? perc = 0: null;  
this.\_width = vol\_back.\_width_perc;  
volume = Math.round(perc_100);  
MySound.setVolume(volume);  
top.equalizer.\_yscale = volume; }; };  
vol\_back.onRelease = vol\_back.onReleaseOutside=function () {  
delete vol\_front.onEnterFrame; };  
vol\_front.setMask(vol\_mask);

// drawing equalizer in actionscript  
top.equalizer.setMask(top.eq\_mask);  
top.equalizer.onEnterFrame = function() {  
i++;  
this.createEmptyMovieClip(“graph”+i, i);  
with(this[“graph”+i]) {  
\_x = 0;  
\_y = 0;  
beginFill(0x666666, 50);  
moveTo(0,0);  
for (j=0; j\< 36; j++) {  
z = random(12)+8;  
lineTo(j_6,-1);  
lineTo(j_6,-z);  
lineTo(j_6+4,-z);  
lineTo(j_6+4,-1);  
lineTo(j_6,-1); }  
lineTo(j_6,0);  
lineTo(0,0);  
endFill(); }  
i \>= 3 ? i=0: null; };

// scrolling the display song title  
function scrollTitle() {  
top.title.txt.autoSize = true;  
if (songTitel[current\_song-1].length \> 20) {  
top.title.txt.text = songTitel[current\_song-1]+" "+songTitel[current\_song-1];  
top.title.\_x+top.title.\_width/2 +4\< top.title\_mask.\_x ? top.title.\_x = top.title\_mask.\_x : top.title.\_x–; }  
else {  
top.title.txt.text = songTitel[current\_song-1];  
top.title.\_x = top.title\_mask.\_x-3; } }  
top.title.setMask(top.title\_mask);  
setInterval(scrollTitle, 40);

// easing display and playlist movement  
MovieClip.prototype.easeY = function(t) {  
this.onEnterFrame = function() {  
this.\_y = int(t-(t-this.\_y)/1.5);  
if (this.\_y\>t-1 && this.\_y\<t+1) {  
delete this.onEnterFrame; } }; };  
//  
Attachment:

---

<div class="post-metadata">

### Author: ![abmed](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@abmed](https://forum.kirupa.com/u/abmed)
#### Post date: [October 15, 2014, 7:36pm UTC](https://forum.kirupa.com/t/counter-of-tracks/351916/2 "2014-10-15T19:36:01Z")

</div>

I found the solution, so it is resolved.  
Thank you for everything.
