I had the text tweening from grey to blue on rollover, and blue back to grey on rollout, but I'd like to optimize the script so that if you rollout before the tween is finished, it will start tweening from the color that it is at in the tween as opposed to the end color, so it wont be jumpy if you rollout quickly.
this is my code:
import flash.filters.GlowFilter;
import mx.transitions.Tween;
import flash.geom.ColorTransform;
MovieClip.prototype.changeColor = function(startColor,endColor){
var target:String = this;
var c:ColorTransform = this.colorInit;
trace (c.rgb.toString(16));
c.rgb = startColor;
var sR:Number = c.redOffset;
var sG:Number = c.greenOffset;
var sB:Number = c.blueOffset;
var clrR:Tween = new Tween(c, "redOffset", none, sR, sR, 1, true);
var clrG:Tween = new Tween(c, "greenOffset", none, sG, sG, 1, true);
var clrB:Tween = new Tween(c, "blueOffset", none, sB, sB, 1, true);
c.rgb = endColor;
var eR:Number = c.redOffset;
var eG:Number = c.greenOffset;
var eB:Number = c.blueOffset;
clrR.continueTo(eR, 1);
clrG.continueTo(eG, 1);
clrB.continueTo(eB, 1);
clrR.onMotionChanged = function() {
var clipColor = new Color(target);
clipColor.setRGB("0x" + c.rgb.toString(16));
};
}
var overTweens:Function = function(target,arr){
var t:MovieClip = this[target];
t.changeColor("0x" + t.colorInit.rgb.toString(16),"0x001B30");
}
var outTweens:Function = function(target,arr){
var t:MovieClip = this[target];
t.changeColor("0x" + t.colorInit.rgb.toString(16),"0x706E6E");
}
var navArray:Array = new Array("link one", "link two", "link three", "link four", "link five");
x=0;
tx=0;
var namesArray:Array = new Array();
for (i=0;i
niMc._x = x;
niMc._y = 110;
var nI:TextField = niMc.createTextField("navText"+i,i,0,0,200,25);
nI.htmlText = navArray[i].toUpperCase();
nI.autoSize = "left";
nI.embedFonts = true;
nI.selectable = false;
nI.html = true;
var nFmt:TextFormat = new TextFormat();
nFmt.color = 0x706E6E;
nFmt.font = "nav_font";
nFmt.size = 16;
nFmt.letterSpacing = 1;
nI.setTextFormat(nFmt);
tx += niMc._width+10;
x = tx;
//apply glow filter
var filter:GlowFilter = new GlowFilter(0x0A0A0A, .53, 3, 3, 1, 3, false, false);
var filterArray:Array = new Array();
filterArray.push(filter);
nI.filters = new Array(filter);
niMc.colorInit = new ColorTransform(0, 0, 0, 1, 112, 110, 110, 0);
namesArray.push(niMc._name);
niMc.onRollOver = function(){
overTweens(this._name,namesArray);
}
niMc.onRollOut = function(){
outTweens(this._name,namesArray);
}
}
So it works if you rollOver and wait for the tween to finish, it even works if the tween is almost finished, but if you rollOver and then rollOut quick, it like changes color to some pinks and cyans... should I tween the alpha multiplier or alpha offset somehow to correct this?
Plus I had a fight with my girlfriend at that moment.
//I'm curious more than anything what went wrong with my code... seemed to me like it should have worked! I suppose I have to reassign the glow filter onMotionChanged? For some reason it disappears...
import flash.geom.ColorTransform;
import mx.transitions.Tween;
mc.ct = new ColorTransform();
mc.redOffsetTween = new Tween(mc.ct, "redOffset", null, 0, 0, 1, true);
mc.greenOffsetTween = new Tween(mc.ct, "greenOffset", null, 0, 0, 1, true);
mc.blueOffsetTween = new Tween(mc.ct, "blueOffset", null, 0, 0, 1, true);
mc.redOffsetTween.onMotionChanged = function():Void {
mc.transform.colorTransform = mc.ct;
}
mc.onRollOver = function():Void {
this.redOffsetTween.continueTo(0, 1);
this.greenOffsetTween.continueTo(0x1B, 1);
this.blueOffsetTween.continueTo(0x30, 1);
}
mc.onRollOut = function():Void {
this.redOffsetTween.continueTo(0x70, 1);
this.greenOffsetTween.continueTo(0x6E, 1);
this.blueOffsetTween.continueTo(0x6E, 1);
}
Although, it shouldnt matter what the values of the tween are since you're not really tweening it until you call the continueTo() method, if you dont set them initially in the tween itself, it messes up somehow: thanks again for your help!
Ive checked the rgb value of the colorTransform object and it is always correct when the tween is finished. However, the color of the mc itself is quite different...
It seems to be a fairly simple code, and Im pretty new at these functions so Im not really sure where to look, any advice?
#If you have any other info about this subject , Please add it free.# |
edit