View Full Version : How do I do variable speed streaming text?
Pixelmech
August 19th, 2006, 11:44 AM
Hi there,
I need to have a stream of binary 0's and 1's going across a text box (I suppose it could be images too, it doesn't really matter). Kind of like a news ticker I suppose. I need to be able to have like 9 instances of this, looking all the same but some going faster and some going slower.
It would need to be contained inside a certain area - so its not text going across the screen, but its text scrolling inside an area - again like a news ticker.
I have no idea how to approach this - I'm assuming AS of course, but if someone could get me started that would be great.
It would be best if I could do it somehow in a text field, as the streams really need to be at different angles (there are 9 of them shooting out from a large box on the left, to a smaller box on the right.)
Thanks!
Tom
Krilnon
August 19th, 2006, 12:42 PM
Something like this, perhaps?
TextField.prototype.scrollText = function():Void {
this.charList = new Array("0", "1");
this.charLength = 50;
if (this.text == "") {
for (i=0; i<this.charLength; i++) {
this.text += this.charList[Math.floor(Math.random()*this.charList.length)];
}
} else {
this.text = this.text.substr(1, this.text.length-1);
this.text += this.charList[Math.floor(Math.random()*this.charList.length)];
}
};
for (i=0; i<9; i++) {
createTextField("my"+i+"_txt", i, 0, 5+(20*i), 200, 20);
this["my"+i+"_txtSpeed"] = setInterval(this["my"+i+"_txt"], "scrollText", Math.floor(Math.random()*190+10));
}
Be careful when rotating the text, you should make sure that the font is embedded first.
Pixelmech
August 19th, 2006, 01:19 PM
Ah, that's about exactly it! Great - now one question though. You've dynamically fired them up at the creation of the movie. How can I apply the function scrollText() to the text field I already have in my document?
So, for example I have a text field named "scroller1" - I am guessing I make it a dynamic text field, and embed the font as you stated - but how to I apply the function to it?
Thanks!
Krilnon
August 19th, 2006, 01:53 PM
Well, since 'scroller1' is the instance name of the TextField, place this somewhere after you define the scrollText method.
var scroller1Speed:Number = setInterval(scroller1, "scrollText", 30);
The last argument in the setInterval call is how often the text should scroll over once, so in this case it is doing so every 30 milliseconds.
Pixelmech
August 21st, 2006, 11:54 AM
Great - that works. Could you explain or point me to a reference describing
:Number
? Not familiar with that.
Only thing now is it seems to scroll from right to left, but I need it to scroll from left to right. Can it be flipped around? Thanks for the help!
grimdeath
August 21st, 2006, 01:24 PM
Great - that works. Could you explain or point me to a reference describing
:Number
? Not familiar with that.
Only thing now is it seems to scroll from right to left, but I need it to scroll from left to right. Can it be flipped around? Thanks for the help!
What :Number does is state that the variables value can only be a number.
Hope that answers your question
Krilnon
August 21st, 2006, 02:00 PM
Only thing now is it seems to scroll from right to left, but I need it to scroll from left to right. Can it be flipped around? Thanks for the help!
TextField.prototype.scrollText = function():Void {
this.charList = new Array("0", "1");
this.charLength = 50;
if (this.text == "") {
for (i=0; i<this.charLength; i++) {
this.text += this.charList[Math.floor(Math.random()*this.charList.length)];
}
} else {
this.text = this.text.substr(0, this.text.length-1);
this.text = this.charList[Math.floor(Math.random()*this.charList.length)]+this.text;
}
};
for (i=0; i<9; i++) {
createTextField("my"+i+"_txt", i, 0, 5+(20*i), 200, 20);
this["my"+i+"_txtSpeed"] = setInterval(this["my"+i+"_txt"], "scrollText", Math.floor(Math.random()*190+10));
}
Pixelmech
August 21st, 2006, 03:34 PM
Great, thank you both!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.