# Marquee scroll dynamic text (song title) from XML file in an MP3 player

**URL:** <https://forum.kirupa.com/t/marquee-scroll-dynamic-text-song-title-from-xml-file-in-an-mp3-player/211666>\
**Category:** flash\
**Created:** [January 4, 2007, 1:16am UTC](https://forum.kirupa.com/t/marquee-scroll-dynamic-text-song-title-from-xml-file-in-an-mp3-player/211666 "2007-01-04T01:16:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![levine2112](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@levine2112](https://forum.kirupa.com/u/levine2112)\
**Post date:** [January 4, 2007, 1:16am UTC](https://forum.kirupa.com/t/marquee-scroll-dynamic-text-song-title-from-xml-file-in-an-mp3-player/211666/1 "2007-01-04T01:16:19Z")

</div>

So I made some a nifty a MP3 player that grabs songs from an XML file. It displays the song name in the dynamic text field. Unfortunately, I only have very little display space and many of the track names are long. The solution: marquee scroll the text horizonally. The problem: I never marquee scrolled dynamic text and now I am lost. I am looking for some advice please.

Here is my main AS:

stop();  
playlist = new XML();  
playlist.ignoreWhite = true;  
playlist.onLoad = function(success) {  
if (success) {  
\_global.songname = [];  
\_global.songband = [];  
\_global.songfile = [];  
for (var i = 0; i\<playlist.firstChild.childNodes.length; i++) {  
\_global.songname\* = playlist.firstChild.childNodes\*.attributes.name;  
\_global.songfile\* = playlist.firstChild.childNodes\*.attributes.file;  
trace(songname\*+" "+songfile\*);  
}  
}  
\_root.createEmptyMovieClip(“sound\_mc”, 1);  
\_root.sound\_mc.sound\_obj = new Sound();  
\_global.song\_nr = random(songfile.length);  
\_root.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
MovieClip.prototype.songStarter = function(file, name) {  
this.sound\_obj.loadSound(file, true);  
this.onEnterFrame = function() {  
if (this.sound\_obj.position\>0) {  
delete this.onEnterFrame;  
this.\_parent.display\_txt.text = name;  
} else {  
this.\_parent.display\_txt.text = “loading…”;  
}  
};  
this.sound\_obj.onSoundComplete = function() {  
(song\_nr == songfile.length-1) ? \_global.song\_nr=0 : \_global.song\_nr++;  
\_root.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
};  
btn\_play.onRelease = function() {  
this.\_parent.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
btn\_stop.onRelease = function() {  
this.\_parent.sound\_mc.sound\_obj.stop();  
};  
btn\_fw.onRelease = function() {  
(song\_nr == songfile.length-1) ? \_global.song\_nr=0 : \_global.song\_nr++;  
\_root.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
btn\_rev.onRelease = function() {  
(song\_nr == 0) ? \_global.song\_nr=songfile.length-1 : \_global.song\_nr–;  
\_root.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
playlist.load(“playlist.xml”);

So yeah, this works fantastic. Now how do I marquee?

I tried dropping the following code in directly after this line… this.\_parent.display\_txt.text = name; :

l = 25;  
x = 0;  
stringOf = function (c, l) {  
var temp = “”;  
for (var x = 0; x\<l; x++) {  
temp += c;  
}  
return temp;  
};  
name = stringOf(" ", l)+name;  
display = function () {  
var temp = name.slice(x, l);  
display\_txt.text = temp;  
x++;  
l++;  
if (x == name.length) {  
x = 0;  
l = 25;  
}  
};  
setInterval(display, 200);  
stop();

And while this did make the text scroll on the first song, it doesn’t work so hot on the second song. It blips back-and-forth between the first and second song name. Advance to a third song and you’ve got an even bigger blipping mess. I kind of think that this code above isn’t the way to go… that it isn’t even worth reworking… that I should try something completely new. Anyone have any thoughts?
