P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Color
:
Simple FadeColor&Alpha for MC - Fade movieClip's color &/or alpha, with callback function
author:
gAntico {alt123}
[+]
,
Submitted: 02.23.04 3p
• Last Edit: 05.24.04 4p
Avg. Rating: 5
//===========================================================================================// // F A D E C O L O R (& A L P H A) 1 . 1 //===========================================================================================// // 25/05/2004 { tested with Flash 6, Flash 7, AS1 and AS2 } // by Giovanni Antico { www.alt123.com } // extending Senocular's blendRGB (http://proto.layer51.com/d.aspx?f=618) //-------------------------------------------------------------------------------------------// MovieClip.prototype.fadeColor = function (finalColor, finalAlpha, speed, callback) { this.percentage = 0; clearInterval (this.fadeInt); this.tmpColor = new Color (this); this.deltaAlpha = finalAlpha - this._alpha; this.startAlpha = this._alpha; this.fade = function (target_MC) { if (target_MC.percentage >= 1) { target_MC.startColor = finalColor; target_MC._alpha = finalAlpha; clearInterval (target_MC.fadeInt); callback (); } else { target_MC.percentage += speed; target_MC.tmpColor.blendRGB(target_MC.startColor, finalColor, target_MC.percentage); if (target_MC.deltaAlpha != 0) { target_MC._alpha = target_MC.startAlpha + (target_MC.deltaAlpha * target_MC.percentage); } } } this.fadeInt= setInterval (this.fade, 40, this); } // Hide the function and the related properties to the for in loops ASSetPropFlags(MovieClip.prototype, "fadeColor", 1, 0); //===========================================================================================// // Senocular's blendRGB function (http://proto.layer51.com/d.aspx?f=618) //-------------------------------------------------------------------------------------------// Color.prototype.blendRGB = function(c1,c2,t){ if (arguments.length == 2){ t = c2; c2 = this.getRGB(); } if (t<-1) t=-1; else if (t>1) t=1; if (t<0) t=1+t; c1 = c1.HEXtoRGB(); c2 = c2.HEXtoRGB(); var ct = (c1.rb+(c2.rb-c1.rb)*t) << 16 | (c1.gb+(c2.gb-c1.gb)*t) << 8 | (c1.bb+(c2.bb-c1.bb)*t); this.setRGB(ct); return ct; }; Number.prototype.HEXtoRGB = function(){ return {rb:this >> 16, gb:(this >> 8) & 0xff, bb:this & 0xff}; }; //-------------------------------------------------------------------------------------------//
usage
//===========================================================================================// // gAntico { [url="http://www.alt123.com"]www.alt123.com[/url] } //-------------------------------------------------------------------------------------------// /* I used Senocular's blendRGB to create a color and alpha fader for MovieClips. It's quite minimal, but very simple to use and modify. For a full set of options, it might be more effective to use the powerfull Tween prototypes: ([url="http://proto.layer51.com/d.aspx?f=1142"]Tweening prototypes AS2 version [/url]). or [url="http://proto.layer51.com/d.aspx?f=804"]Tween movieclip properties in a clean and easy way, using Robert Penner's easing equations [/url] */ //===========================================================================================// // PARAMETERS //-------------------------------------------------------------------------------------------// // finalColor = the destination colour // finalAlpha = the destination Alpha // speed = values admitted are between 0 and 1 (ex. 0.05, 0.10 or 0.15) // callback = optional function to be called at the end of the fading //===========================================================================================// // USAGE //-------------------------------------------------------------------------------------------// // create a clip named "myMovieClip_mc" and the buttons "sample1_btn" and "sample2_btn" // attach the following code to frame 1 // set the starting color (only the first time); // if not set, the default is black myMovieClip_mc.startColor = 0x252525 // set callback functions to be called when fading is finished function test () { trace ("fading finished"); } // change the movieClip to a semi-transparent yellow sample1_btn.onRelease = function () { myMovieClip_mc.fadeColor (0x009933, 50, .05, test); } // change the movieClip to an opaque azure, slowly sample2_btn.onRelease = function () { myMovieClip_mc.fadeColor (0x0191C7, 100, .02, test); } //-------------------------------------------------------------------------------------------//
msg
1
{
alexmc2
[+]
, posted: 05.21.04 12a•-, top
[^]
}
hi there,
great compliment to your script!
it help me a lot .. this one is very usefull.
great work!
now i would like to add an ASBroadcaster that tell me that the mc is arrived at the color.
if anybody can help me a little that would be great.
have a great time
take care
cheers
alex
msg
2
{
gAntico {alt123}
[+]
, posted: 05.24.04 4p•-, top
[^]
}
Happy to know that it was useful to you.
I've added a callback function: you just need to define it before invoking the prototype. I've updated the usage example too.
;-)
best
gAntico
msg
3
{
alexmc2
[+]
, posted: 05.24.04 11p•05.24.04 11p, top
[^]
}
hi gAntico :)
i only can say one word...... PERFECT!
thanks for helping me so much.
your script works perfect and the explanation is great!
i have learn a lot from your script.
thank you so much.
have a good time and take care and keep on doing such perfect work.
best
alex
msg
4
{
oto_oto
[+]
, posted: 11.30.07 12a•-, top
[^]
}
Yes the script is wonderful but it has one bug, first time you call the function it doesn't make color change only second times and after..
msg
5
{
KarlFreeman
[+]
, posted: 04.02.08 2a•04.02.08 2a, top
[^]
}
Excellent piece of script here from the both of you, thank you very much!!! it works like a dream. :)
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@