hi, i’m looking for a dynamic marquee… this is what i found this far on the forum:
this.createTextField("scroller_txt", 1, 0, 0, 100, 20);
scroller_txt.border = true;
scroller_txt.speed = 1;
scroller_txt.text = "This is the text that will continuously scroll."+"this is also some text that will scroll";
scroller_txt.spaceSize = scroller_txt.getNewTextFormat().getTextExtent(" ").width;
scroller_txt.spacesRequired = Math.ceil(scroller_txt.width/scroller_txt.spaceSize);
for (var i = 0; i<scroller_txt.spacesRequired; i++) {
scroller_txt.spacebuffer += " ";
}
scroller_txt.text = scroller_txt.spacebuffer+scroller_txt.text+scroller_txt.spacebuffer;
scroller_txt.hscrollInterval = function() {
if (this.hscroll == this.maxhscroll) {
this.hscroll = 0;
}
this.hscroll += this.speed;
};
setInterval(scroller_txt, "hscrollInterval", 20);
and it works pretty good… the only thing thats wrong is the undefined in front of the text… i tried a few things but i cant make it disappear… does anybody knows why it appears in the first place? and how to get rid of it?
OK, here’s the deal…
this chunk of code works pretty nicely except for the ‘undefined’ that shows up. the reason ‘undefined’ shows up in the textbox is because initially, it IS undefined, (in the for loop, it is initially equal to itself += which is undefined, THEN it is equal to the right amount of spaces). So, simply define it ahead of time, like this:
scroller_txt.spacebuffer = " ";
So, the whole chunk of code is now this:
this.createTextField("scroller_txt", 1, 0, 0, 100, 20);
scroller_txt.spacebuffer = " ";
scroller_txt.border = true;
scroller_txt.speed = 1;
scroller_txt.text = "This is the text that will continuously scroll."+"this is also some text that will scroll";
scroller_txt.spaceSize = scroller_txt.getNewTextFormat().getTextExtent(" ").width;
scroller_txt.spacesRequired = Math.ceil(scroller_txt._width/scroller_txt.spaceSize);
for (var i = 0; i<scroller_txt.spacesRequired; i++) {
scroller_txt.spacebuffer += " ";
}
scroller_txt.text = scroller_txt.spacebuffer+scroller_txt.text+scroller_txt.spacebuffer;
scroller_txt.hscrollInterval = function() {
if (this.hscroll == this.maxhscroll) {
this.hscroll = 0;
}
this.hscroll += this.speed;
};
setInterval(scroller_txt, "hscrollInterval", 20);
One more thing I forgot to mention…
When returning the width, i had to change .width to ***._width. ***This allowed the script to properly return the width so that the text starts flush right.