Create a Random Animated Color Text Effect

October 3rd, 2009 in Flash

This actionscript 3 tutorial shows you how to create a Random Animated Color Text Effect. Over time each letter changes its color one after the other.

View DemoDownload Source

1. Create a new flash file (Actionscript 3.0) and save it as randomColorText.fla.

2. Rename “layer 1″ to “letters”. Select the Text tool and type your static text on the stage. Set the text properties as you like.
With the text still selected, select in the top menu Modify>Break apart to break your text into separate letters.
Convert each letter to a movie clip. No need to give them instance names.

3. Create a new “actions” layer and open the actions panel.
First declare a Timer variable and set its delay property as you like. Here we choose 100 ms. Next add a TIMER event listener that will be handled by the changeColor function.

var timer:Timer = new Timer(100,0);

timer.addEventListener(TimerEvent.TIMER, changeColor)

4. In the changeColor function, we need to retrieve the current letter which we want to change its color.
To do so, first declare just after the Timer, a current variable as an int and initialize it to 0.
In the function we can now get the current letter.
Next create a ColorTransform object. Then set its color to a random one and apply it to the current movie clip letter.
Finally, we increment the current variable unless we get the last letter and this case, reset to 0.

var current:int = 0;

function changeColor(e:Event):void{
	var mc:MovieClip = getChildAt(current) as MovieClip;
	var myColorTransform : ColorTransform = mc.transform.colorTransform;
	myColorTransform.color=  Math.random() * 0xffffff;
	mc.transform.colorTransform = myColorTransform;
	if(current == numChildren -1)
		current = 0;
	else
		current ++;
}

5. Finally, don’t forget to start the timer by calling the start() method.
Here’s the final code, test your movie to see it in action.

var timer:Timer = new Timer(100, 0);
var current:int = 0;

timer.addEventListener(TimerEvent.TIMER, changeColor);
timer.start();

function changeColor(e:Event):void{
	var mc:MovieClip = getChildAt(current) as MovieClip;
	var myColorTransform : ColorTransform = mc.transform.colorTransform;
	myColorTransform.color=  Math.random() * 0xffffff;
	mc.transform.colorTransform = myColorTransform;
	if(current == numChildren -1)
		current = 0;
	else
		current ++;
}
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Twitter


What you think ...

(7 Comments)

+ Add a Comment
  1. JAP
    Oct 5th, 2009

    How to add background in a Random Animated Color Text Effect.
    Thanks!

  2. kapil
    Oct 5th, 2009

    gooood

  3. Mr. Bond
    Oct 9th, 2009

    Like it!

  4. 45+ Advanced Adobe Flash Actionscript Trainings | Master Design
    Nov 1st, 2009

    [...] Create a Random Animated Color Text Effect [...]

  5. Zach
    Nov 11th, 2009

    Whats the text font used? I like it!

  6. Advanced Adobe Flash Actionscript Trainings « Flash Criminals
    Nov 26th, 2009

    [...] Create a Random Animated Color Text Effect [...]

  7. shoban
    Mar 8th, 2010

    very good animation

Leave a Comment

Name (required)

E-mail (required, will not be published)

Website