hello all,
I have a client that would like to have the site text change color every 5 seconds - the text buttons included. There is only 5 colors they want to cycle through.
I would like to be able to set up an actionscript to handle this so I don’t have to animate each text.
Any ideas how I might do this??
Thanks
krityx
September 29, 2008, 8:15pm
2
var i:Number = 0;
function changeColor()
{
if (i==0) {
i++;
tf.textColor = 0xFF0000;
}else if(i==1){
i++;
tf.textColor = 0xFF0000;
}else if(i==2){
i++;
tf.textColor = 0x552288;
}else if(i==3){
i++;
tf.textColor = 0x7865f2;
}else if(i==4){
i=0;
tf.textColor = 0x162ff6;
}
}
setInterval(changeColor, 5000);
krityx,
What does “tf” refer to?
Do I need to put a call to changeColor() on the actions frame?
Is your method compatible with as3 or as2 ??
Thanks,
ok so I realize that tf is a variable that I have to create for my text fields like:
var tf:TextField = new TextField();
but how do I get this to apply to all my text feilds already created?
samohtwerdna:
ok so I realize that tf is a variable that I have to create for my text fields like:
var tf:TextField = new TextField();
but how do I get this to apply to all my text feilds already created?
Hi.
You must create a Dynamic Text input
named it (in this case) tf then in an other
layer named ie actions put the code
posted by krityx.
Bye.
krityx
October 1, 2008, 8:44pm
6
to apply it to all the textfields the easiest way would be to name each of them sequentially (eg : tf1,tf2,tf3) and then use a for loop .
var i:Number = 0;
var n:Number = 3; //number of textfields
function changeColor()
{
for(var j:uint=1; j<=n; j++){
if (i==0) {
i++;
this["tf"+j].textColor = 0xFF0000;
}else if(i==1){
i++;
this["tf"+j].textColor = 0xFF2233;
}else if(i==2){
i++;
this["tf"+j].textColor = 0x552288;
}else if(i==3){
i++;
this["tf"+j].textColor = 0x7865f2;
}else if(i==4){
i=0;
this["tf"+j].textColor = 0x162ff6;
}
}
}
setInterval(changeColor, 5000);
krityx:
to apply it to all the textfields the easiest way would be to name each of them sequentially (eg : tf1,tf2,tf3) and then use a for loop .
var i:Number = 0;
var n:Number = 3; //number of textfields
function changeColor()
{
for(var j:uint=1; j<=n; j++){
if (i==0) {
i++;
this["tf"+j].textColor = 0xFF0000;
}else if(i==1){
i++;
this["tf"+j].textColor = 0xFF2233;
}else if(i==2){
i++;
this["tf"+j].textColor = 0x552288;
}else if(i==3){
i++;
this["tf"+j].textColor = 0x7865f2;
}else if(i==4){
i=0;
this["tf"+j].textColor = 0x162ff6;
}
}
}
setInterval(changeColor, 5000);
Hi krityx.
Sorry to disturb you,
I’m making my first step
in AS
Why does this script work only
with __root
function circleX(distance:Number, angle:Number):Number {
return distance*Math.sin(Math.PI*angle/6);
}
function circleY(distance:Number, angle:Number):Number {
return -distance*Math.cos(Math.PI*angle/6);
}
var center:Number = 200;
for (var i:Number = 1; i<13; i++) {
duplicateMovieClip(number_txt, "number"+i+"_txt", i);
// position text field
trace(_root["number"+i+"_txt"]);
_root["number"+i+"_txt"]._x = center+circleX(200, i);
_root["number"+i+"_txt"]._y = center+circleY(200, i);
// change text in text field
_root["number"+i+"_txt"].text = i;
}
var i:Number = 0;
var n:Number = 13; //number of textfields
function changeColor()
{
for(var j:Number=1; j<=n; j++){
if (i==0) {
i++;
_root["number"+j+"_txt"].textColor = 0xFF0000;
}else if(i==1){
i++;
_root["number"+j+"_txt"].textColor = 0xFF2233;
}else if(i==2){
i++;
_root["number"+j+"_txt"].textColor = 0x552288;
}else if(i==3){
i++;
_root["number"+j+"_txt"].textColor = 0x7865f2;
}else if(i==4){
i=0;
_root["number"+j+"_txt"].textColor = 0x162ff6;
}
}
}
setInterval(changeColor, 500);
/*
setInterval(changeColor, 1000);
trace(circleX(100, 1));
trace(circleX(100, 2));
trace(circleX(100, 3));
*/
code by http://www.friendsofed.com/book.html?isbn=1590596188
Bye.
Thanks for the help guys,
what about making a smooth transition between the colors instead of the abrput??
I assume the Tween class - but where would I implement it??
ok,
I added this to help the transition
var final_color:Array = new Array();
final_color[0] = 0x999999; //gray
final_color[1] = 0xFF0000; //red
final_color[2] = 0x0066CC; //blue
final_color[3] = 0xFF66CC; //pink
final_color[4] = 0x00CC66; //green
final_color[5] = 0x999999; //gray
alphaOver.addEventListener(TweenEvent.MOTION_CHANGE,tweenToFinal);
function tweenToFinal(event:TweenEvent):void
{
colorInfo.color = Color.interpolateColor(final_color[c],final_color[c+1],event.position);
ex_txt.transform.colorTransform=colorInfo;
}
but now I get a flicker at the end of the interval
what can I do better to make the whole transition smooth??
krityx
October 2, 2008, 8:29am
10
whisher : maybe the reason it only works with _root is because the textfields are on level0 (or _root) . this assumes that the textfields are in the same movieclip or level you’re typing your AS on .