Hi Guys,
I created this class some time ago that pixelates and scrolls text.
Please have a look and let me know what do you think
You can use it this way:
//scrolling_text(text,textSize,velocity,textColour,backgroundColour,charactersWrap,numberOfHorizontalPixels,bannerWidth,bannerHeight,spaceBetweenTiles)
Cheers!
package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.utils.Timer;
public class scrolling_text extends Sprite {
public var textContainer:Sprite;
public var topLabel:TextField;
public var labelTextSize:uint;
public var format:TextFormat;
public var bmd:BitmapData;
public var bm:Bitmap;
public var displayText:String;
public var displayTextwS:String;
public var charactersWrap:uint;
public var charNum:uint;
public var pixelPannelData:BitmapData;
public var pixelPannel:Bitmap;
public var pixelSize:uint;
public var pixelCountH:uint;
public var spaceBetweenTiles:uint;
public var bannerSize:Array;
public var colour:uint;
public var tColour:uint;
public var bColour:uint;
public var xPos:Number;
public var yPos:Number;
public var square:Rectangle;
public var timer:Timer;
public var t:Number;
public var textMask:Shape;
////////// var st:scrolling_text=new scrolling_text(text,textSize,velocity,textColour,backgroundColour,charactersWrap,numberOfHorizontalPixels,bannerWidth,bannerHeight,spaceBetweenTiles)
public function scrolling_text(_displayText:String="Add Some Text",_labelTextSize:uint=60,_t:uint=100,_tColour:uint=16777215,_bColour:uint=0,_charactersWrap:uint=3,_pixelCountH:uint=150,_bannerSize:Array=null,_spaceBetweenTiles:uint=1):void {
//////////////////////// DECLARING VARIABLES ////////////////////
displayText=new String(_displayText);
displayTextwS=new String(" ");
charactersWrap=new uint(_charactersWrap);
labelTextSize=new uint(_labelTextSize);
pixelCountH=new uint(_pixelCountH);
pixelSize=new uint();
if (_bannerSize==null) _bannerSize=[500,400];
bannerSize=_bannerSize;
spaceBetweenTiles=new uint(_spaceBetweenTiles);
colour=new uint();
tColour=new uint(_tColour);
bColour=new uint(_bColour);
xPos=new Number();
yPos=new Number();
t=new Number(_t);
//////////////////////// CREATING THE TEXT CONTAINER ////////////////////
textContainer=new Sprite();
addChild(textContainer);
//////////////////////// CREATING THE TEXTFIELD AND TEXTFORMAT ////////////////////
topLabel = new TextField();
topLabel.autoSize = TextFieldAutoSize.LEFT;
topLabel.border=false;
format= new TextFormat();
format.font = "Courier New";
format.color = 0x000000;
format.size = labelTextSize;
topLabel.defaultTextFormat = format;
textContainer.addChildAt(topLabel,0);
topLabel.text=" ";
//////////////////////// HIDING THE TEXT WITH A SHAPE //////////////////////////////
textMask=new Shape();
textMask.graphics.beginFill(0xFFFFFF);
textMask.graphics.drawRect(0,0,bannerSize[0]*3,bannerSize[1]);
textContainer.addChildAt(textMask,1);
//////////////////// RUN WHEN MOVIE HAS INITIALISED ////////////////////
addEventListener( Event.ENTER_FRAME , init );
}
public function init(e:Event):void {
//////////////////////// DECLARING VARIBALES /////////////////////
charNum=new uint(Math.round(bannerSize[0]/topLabel.getCharBoundaries(0).width));
pixelSize=bannerSize[0]/pixelCountH;
//////////////////////// CREATING THE BITMAPS ////////////////////
bmd= new BitmapData(bannerSize[0],bannerSize[1],false,0xFFFFFF);
bm= new Bitmap(bmd);
textContainer.addChildAt(bm,2);
//////////////////////// CREATING THE PIXELATION BORDERS ////////////////////
pixelPannelData=new BitmapData(bannerSize[0],bannerSize[1],false,0xFFFFFF);
pixelPannel= new Bitmap(pixelPannelData);
textContainer.addChildAt(pixelPannel,3);
for (var l:uint=new uint(1); l<charNum; l++) {
displayTextwS+=" ";
}
displayTextwS+=displayText;
topLabel.text=displayTextwS;
//////////////////// SETTING THE TIMER ////////////////////////////////
timer = new Timer(t, 0);
timer.start();
timer.addEventListener(TimerEvent.TIMER, timerListener);
//////////////////////////////REMOVE THIS LISTENER ////////////////////////
removeEventListener( Event.ENTER_FRAME , init );
}
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// SET TEXT //////////////////////////////////////////////////
public function setText(newText:String):void{
//////////////////// REMOVE THE TIMER ////////////////////////////////
timer.removeEventListener(TimerEvent.TIMER, timerListener);
trace(newText);
//////////////////////// DECLARING VARIBALES /////////////////////
displayText=newText;
displayTextwS=" ";
for (var l:uint=new uint(1); l<charNum; l++) {
displayTextwS+=" ";
}
displayTextwS+=displayText;
topLabel.text=displayTextwS;
timer.addEventListener(TimerEvent.TIMER, timerListener);
}
///////////////////////// EVENT HANDLER //////////////////////////////////////
public function timerListener(e:Event):void {
bmd.fillRect(bmd.rect,0xFFFFFF);
bmd.draw(topLabel);
for (var n:uint=new uint(0); n<Math.ceil(bannerSize[1]/(pixelSize+spaceBetweenTiles)); n++) {
for (var k:uint=new uint(0); k<pixelCountH; k++) {
xPos=k*(pixelSize+spaceBetweenTiles)+spaceBetweenTiles-1;
yPos=n*(pixelSize+spaceBetweenTiles)+spaceBetweenTiles-1;
//////////////////////// GETTING THE PIXEL COLOUR VALUES ////////
pixelPannelData.lock();
colour= bmd.getPixel(xPos,yPos);
if (colour!=16777215) {
colour=tColour;
} else {
colour=bColour;
}
square= new Rectangle(xPos,yPos,pixelSize,pixelSize);
pixelPannelData.fillRect(square,colour);
pixelPannelData.unlock();
}
}
//////////////// REPLACE THE FIRST LETTER WITH "" AND ADD SPACE BEHIND ///////////////////
topLabel.replaceText(0,1,"");
//////////////// WHEN IT REACHES THE END ADD THE NEW TEXT ///////////////////
if (topLabel.getLineLength(0)==displayText.length) {
for (var l:uint=new uint(1); l<charNum-displayText.length+charactersWrap; l++) {
topLabel.appendText(" ");
}
topLabel.appendText(displayText);
}
}
}
}