Skip to main content
Inspiring
September 12, 2006
Question

Horizontal Scroll Text

  • September 12, 2006
  • 6 replies
  • 410 views
I found a cool new font and would like to scroll text like a news ticker. I have created my dynamic text box, set it up the way i want the text to look, and set it to scroll. I know how to write the code for a vertical scroll, how would i set it up to scroll horizontally?

the text in the text box wants to set itself up as vertical lines instead of horizontally as well. How can i change that? Thanks for the help.

Josh
This topic has been closed for replies.

6 replies

Inspiring
September 13, 2006
BTW...you can adjust the speed and smoothness of the scroll by changing
these two lines:

horizontal_txt._x -=20; // smoother = lower number

and

intervalId = setInterval(this, "scrollMe", 100); // 100 is how many
milliseconds inbetween each function call - lower = faster


Inspiring
September 13, 2006
Here's some code for a horizontal text scroller I just threw together.

horizontal_txt.autoSize = "left";

horizontal_txt.text = "Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged.";

var intervalId:Number;

function scrollMe():Void {
horizontal_txt._x -=20;
if (horizontal_txt._x <= -horizontal_txt.textWidth) {
horizontal_txt._x = 550;
}
}

intervalId = setInterval(this, "scrollMe", 100);

//////////////////////
Basically, I'm just moving the text box -20 pixels in the _x position each
time the function is called (you can mask it if you'd like).

Once it determines that the inverse of the width of the text in the textbox
is less than or equal to it's _x position, it resets the textbox back to the
right edge of the play area.

To test, just make a dynamic, single line textbox named horizontal_txt and
place it at 550 on the stage.

You could get more sophisticated and have an array of news that it cycles
through, and have it pause if the mouse of over, etc. I'm sure you've seen
those things before.

Anyway...let me know if you have any problems implementing.

- Chris


Inspiring
September 13, 2006
I made a mistake in my first post. You should have autoSize ="left".

That's why it's showing the end of the string.


Inspiring
September 13, 2006
Do you mean that all of the text is there but it scrolls to the last line of
text you entered - or - do you mean the only thing in the textbox is the
last line of text?

If it's the latter, then you're using textField.text = "string", instead of
textField.text += "string".

If you want it to repeat in an endless loop, i'll post that in a sec.


Inspiring
September 13, 2006
I am using the code as listed above with the text_txt.hscroll +=20;

i would like it to continuously scroll at a speed i can control, Is that possible?
Inspiring
September 13, 2006
thanks for the help.

when i use that code, it just shows the last line of my text. How can i set it up to repeat all the text and automatically scroll through all?
Inspiring
September 12, 2006
To change the expansion of the TextField from vertical to horizontal, you
need to use the autoSize method:
[TextField instance name].autoSize = "right";

To scroll horizontally, you simply use the hscroll method:
[TextField instance name].hscroll += 20;

LiveDocs hscroll documentation:
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002750.html

LiveDocs autoSize documentation:
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002734.html

HTH,

Chris