What about this? I added a whole bunch of garbage to the fade function to
show flexibility. You could trim the fat by eliminating most of the
arguments passed.
this.template.fade=function (dest:Number, //this is the alpha value you
want to fade TO
frame:Number, //this is the number
of frames it should take
delay:Number, //this is a delay
before the fade starts (used for sequential fading effect
funcname:String, //this is the name
of a predefined callback function in the same scope
arg:Object, //this is an optional
argument to be passed to the callback function
del:Boolean) { //allows the clip to
remove the fade function so it only fades once
this.destAlpha=dest;
this.fadeRate=((this._alpha-dest)/frame)||dest>this._alpha?1:-1;
this.fadeFunc=funcname;
this.fadeDelay=delay;
this.fadeDelete=del;
this.fadeArg=arg;
this.onEnterFrame=function () {
if (this.delay) {
this.delay--;
} else {
var diffAlpha:Number=this._alpha-this.destAlpha;
trace (diffAlpha);
if (Math.abs(diffAlpha)<2) {
this._alpha=this.destAlpha;
delete this.fadeDelay
delete this.fadeRate;
delete this.destAlpha;
delete this.onEnterFrame;
var callback:String=this.fadeFunc;
var arg=this.fadeArg;
delete this.fadeArg;
this[callback](arg);
if (this.fadeDelete) {
delete this.fadeDelete;
delete this.fade;
}
delete this.fadeFunc;
}
this._alpha+=this.fadeRate;
}
}
}
//used only to show the callback optional feature.
this.template.changeColor=function (num:Number) {
trace ("changing color "+num);
var clr:Color=new Color(this);
clr.setRGB(num);
}
var numCopies:Number=5;
for (var i=0;i<numCopies;i++) {
var nm:String = "template"+i.toString(); //name
var dp:Number=this.getNextHighestDepth(); //depth
var yp:Number=i*50; //"Y" position
var init:Object={_y:yp, fade:this.template.fade, changeColor:
this.template.changeColor, _alpha:0};
this.template.duplicateMovieClip(nm,dp,init);
this[nm].fade(100,40,80,"changeColor",Math.random()*0xffffff, true);
}
stop();
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com