Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : textColor and mx.transitions.Tween


s007767
6/28/2006 11:11:33 PM
I'd like to fade some text from 0xFF00CC to 0xFFFFFF in Flash 8. I tried using
the Tween object to accomplish this.

var showTween2 = new mx.transitions.Tween (clip.textClip.menuText,
"textColor", null, 0xFF00CC, 0xFFFFFF, .75, true);

menuText is a dynamic text field.

It starts and ends where it should, but instead of fading it flickers back and
forth between the two values. Am I to infer that textColor doesn't work with
the Tween object? Is there a generally accepted method of tweening font colors
with out using tint?

-Sean
See4th
6/28/2006 11:57:00 PM
Here's the Pixelwit ColorFader.as class. Put it in your Flash install dir. Ex:
C:\Program Files\Macromedia\Flash 8\en\First Run\Classes\pixelwit\ColorFader.as

Then at the top of the page where it will be call place:
[b]import pixelwit.ColorFader.as;[/b]

Call it like this:
[b]myColor = new ColorFader(myText);[/b] // myText being the object to
receive the color fade
[b]myColor.fadeHex (0xFFFFFF, 2000);[/b] // 1st param the color going to,
2nd param fade rate in ms




class ColorFader extends Color{

private var v:Object;
private var intervalId:Number

public function ColorFader(mc:MovieClip){
super(mc);
}

private function transObjSame(obj1:Object, obj2:Object):Boolean{
for(var i in obj1){
if(obj1[i] != obj2[i]){
return false;
}
}
return true;
}

private function fadeTransform(goalTrans:Object, milSecs:Number,
func:Function):Void{
if(this.v){
if( this.transObjSame(goalTrans, this.v.goalTrans)){
return;// already heading to that trans obj so
just wait
}else{
clearInterval(this.intervalId);
}
}
var getTrans = this.getTransform();
if(this.transObjSame(goalTrans, getTrans)){
trace("already there");
return;// already at that trans obj so don't bother
}
this.v = {};
this.v.goalTrans = goalTrans;
this.v.milSecs = milSecs;
if(typeof func == "function")this.v.func = func;
this.v.startTime = getTimer();
this.v.startTrans = getTrans;
this.v.change = {};
for(var i in goalTrans){
this.v.change[i] = goalTrans[i]-this.v.startTrans[i];
}
this.transShift();
if(milSecs){
this.intervalId = setInterval(this,"transShift",10);
}
}

private function transShift(Void):Void{
var ratio = (getTimer()-this.v.startTime)/this.v.milSecs;
if(ratio<1){
var newTrans = {};
for(var i in this.v.change){
newTrans[i] =
this.v.startTrans[i]+ratio*this.v.change[i];
}
this.setTransform(newTrans);
}else{
this.setTransform(this.v.goalTrans);
clearInterval(this.intervalId);
var myFunc = this.v.func;
delete(this.v);
if(myFunc)myFunc();
}
}
public function fadeRGB (r:Number, g:Number, b:Number, milSecs:Number,
func:Function):Void{
var goalTrans = {ra:0, ga:0, ba:0, rb:r, gb:g, bb:b, aa:100,
ab:0};
this.fadeTransform(goalTrans, milSecs, func);
}
public function fadeHex(goalHex:Number, milSecs:Number,
func:Function):Void{
var goalRGB = this.hexToRGB(goalHex);
this.fadeRGB(goalRGB.r, goalRGB.g, goalRGB.b, milSecs, func);
}
public function fadeClearTrans(milSecs:Number, func:Function):Void{
var goalTrans = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0,
aa:100, ab:0};
this.fadeTransform(goalTrans, milSecs, func);
}
// PiXELWiT REVERSE ENGINEERING
private function hexToRGB(hex:Number):Object{
var red = hex>>16;
var grnBlu = hex-(red<<16)
var grn = grnBlu>>8;
var blu = grnBlu-(grn<<8);
return({r:red, g:grn, b:blu});
}

}
AddThis Social Bookmark Button