ActionScript CountTelexTF class
Some years ago I coded a promotional intro for the democode forum called DBF+GVY Interactive. This tiny intro called A shameless plug uses a certain typer/text effect to show its messages. The text effect isn’t new at all - if you know the 80’s movie called “Wargames” you probably remember it. It was used when the supercomputer called W.O.P.R. was searching for the right missle launch code.
Well, the following C++ code is nearly two years old.
// // the basic algorithm/idea behind the text effect used // in the dbfinteractive promo intro downloadable at : // http://dbfinteractive.com/index.php?action=tpmod;dl=item53 // // (c) 2oo7 by benny!weltenkonstrukteur.de // #include #include int telexTyper ( char *pMsg, char *pTelexText ) { // telexTyper returns 1 when message equals telexText // else 0. It is assumed that MSG and TELEXTEXT are of // the same length !!! int ret = 1; // loop the the telex text for ( int i=0; i < strlen(pTelexText); i++ ) { int ascii_Msg = (int)*pMsg; // get ascii value of char (scrollText) int ascii_Tex = (int)pTelexText[i]; // get ascii value of char (telexText) if ( ascii_Msg < ascii_Tex ){ // substract ascii value by 1 ascii_Tex--; ret = 0; } else if ( ascii_Msg > ascii_Tex ) { // or add ascii value by 1 ascii_Tex++; ret = 0; } pTelexText[i] = (char)ascii_Tex; pMsg++; } printf ( "%s\n", pTelexText ); return ret; } int main( ) { // telexText holds the characters that are displayed char telexText[7] = "AAAAA\0"; // the scroller array hold the actual text char scroller[2][7]= { "HELLO\0", "WORLD\0" }; // we loop as long as telexTyper return 1 // returning 1 means that the characters in the source array scroller // are equal to the characters in the destination array telexText while ( telexTyper ( &scroller[0][0], &telexText[0] ) == 0 ); printf ( "\nFirst scrolltext successfully displayed!\n\n" ); while ( telexTyper ( &scroller[1][0], &telexText[0] ) == 0 ); printf ( "\nSecond scrolltext successfully displayed!\n" ); // end - wait for keypress getchar(); return 0; }
However, today I thought it would be nice to write a similar effect in Flash. So, I extended the textfield class and came up with the CountTelexTF class. This class actually does all you need to realize the effect. The class file is too long to be listed here - but have a look at the following demo programm that makes use of the new class:
package { import flash.events.*; import flash.display.Sprite; import flash.filters.GlowFilter; import flash.text.*; import de.weltenkonstrukteur.utils.CountTelexTF; /** * Demo of CountTelexTF class usage * @author benny!weltenkonstrukteur.de */ public class Main extends Sprite { // Specify font [Embed(source='Crisp.ttf', fontName='Crisp', fontWeight='normal', mimeType='application/x-font-truetype')] private var telexFont:Class; // Member variables private var cntTf:CountTelexTF = null; /** * Constructor */ public function Main() { // Register font Font.registerFont(telexFont); var tfo:TextFormat = new TextFormat('Crisp', 36, 0x00ff00); // Create CountTelexTF instance cntTf = new CountTelexTF(); cntTf.width = stage.stageWidth; cntTf.y = 50; cntTf.autoSize = TextFieldAutoSize.CENTER; cntTf.defaultTextFormat = tfo; cntTf.embedFonts = true; // Add some glow filter var glow:GlowFilter = new GlowFilter( 0x00CC00, 0.8, 35, 35, 4); cntTf.filters = [glow]; // Create and set string array var myText:Array = new Array(); myText[0] = "Whatever Keeps Us Longing "; myText[1] = "For Another Breath Of Air "; myText[2] = " Is Getting Rare "; myText[3] = "But Is Has To Be Somewhere"; myText[4] = " "; cntTf.setTextArr(myText); addChild(cntTf); cntTf.start(); } } }
The result looks like this:
Of course it is recommended to use a monospace font with this effect. Otherwise it looks a bit jerky. You can download the example and the class itself with the following link. Enjoy.
Name: ActionScript CountTelex Class
Size: 3.56 KB
Hits: 96

