For one of my work I had to write one “Animation of writing a sentence”. I googled around for some time and found creating movie clip with each frame consisting of writing couple of character or part of character painted to accomplish the animation.
The problem with this is I have to do lot of work if string has around 600 Character and also file size will be enormous, brighter side is that the motion will be smoother. After brainstorming I finally came up with some code than can accomplish the animation task, but this code works fine with some particular value of sec. As sec value decreases the motion is horrible. People with more knowledge on AS3 (more like guru in AS3) can improve this. Without further delay here is the code. here I’m loading data from a external text field, and after loading I’m assigning this to c=variable string.
var string:String = textloader.data.substr(0,550);
var lengt:int = string.length;
var sec:int = 3;
var interval:Number = lengt/(sec*1);
var nochar:int = lengt/interval;
var intcomp:int = 0;
var incchar:int = nochar;
var timefram:Number = (sec*1000)/interval;
var time:Timer = new Timer(timefram, 1);
time.start();
time.addEventListener(TimerEvent.TIMER_COMPLETE, animate);
function animate(e:TimerEvent):void
{
intro_txt.text=string.substr(0,incchar);
incchar += nochar;
if(intcomp <= interval)
{
intcomp++;
time.start();
}
}
I hope this works for you. Please feel free to comment if you have any suggestion on improvement. I have not provided the interval parameter while creating time object because I had problems, so i came up with a work around with an if(intcomp <= interval) condition.