MovieClip.prototype.fadeTo = function(value, speed) { };
A prototype is like a normal function, however it has one very significant difference.... it is object oriented. In this case the object is a MovieClip symbol. That means to properly use this function it must be attached to an instance of a movieclip symbol, hence why you call the function as "clipInstanceName.functionName();". Since prototypes are global you don't target them like you do normal functions (_root.functionName(), etc).
this.onEnterFrame = function() {};
The onEnterFrame handler is an object specific dynamic event handler. It is the dynamic form of "onClipEvent(enterFrame){}".
this.aV = Math.floor(value-this._alpha);
this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
- this.aV = Math.floor(value-this._alpha);
- this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
Now this is the more complicated stuff. I wrote two tutorials on easing in Flash, they both use the same formula, but show the basic method, which the ideas in the equation can be applied to more than just _x and _y positions (as we see in this alpha fade). Here are the tutorials...
Tutorial 1Tutorial 2As I stated, the tutorials apply easing to a clips position, but the ideas of the equation are not limited to that, so in this case I brought it to changing the alpha value of a clip.
There are a few sligh differences in how I wrote it. The basic easing equation is set up as
_property += (endValue-_property)/speed;
However, in the case of alpha fading, I wanted to delete the onEnterFrame handler (only possible in a dynamic event handler, not an onClipEvent handler) after the fade was completed. With the standard easing equation, the numbers it produces requires a cheap workaround to achieve this. So I seperated the "(endValue-_property)" part from the equation and chose to hold it in it's own variable.
The variable in this case is "this.aV" (which to me stands for alpha value), the "this" locator in front of the variable assures that the variable is created within the object calling the function. This is the joy of variable scopes. If you don't have "this" there the variable will be the same value for any clip running this function. The use of "this" assures you can use this on more than one clip at a time because each clip will be reading the value of the variable contained within itself.
I chose to Math.floor() the "(endValue-_property)" part so I wouldn't have to deal with 8 place decimals numbers. A nice round number is what i'm looking for, but I want it to round down so it can hit 0 better.
this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
This line right here is probably the most confusing to you. But I hope to clear it up.
The main part that is probably what is confusing about this line is the crap about "?" and ":". A very handy shortcut in many programming languages is what is called the tertiary operator (
http://www.kirupa.com/developer/actions ... rtiary.htm ). It is a shorthand form of an if/else statement
That basically says if statement is true, do A, else do B.
So now that you hopefully have a better understanding of the tertiary operator, let's get back to the code.
this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
What this says that if the variable this.aV exists/has a value other than 0, the alpha should adjust itself via the basic easing equation. Else if this.aV doesn't exist or is equal to 0, the alpha value of this clip will be set to the value you wanted, and the onEnterFrame dynamic event handler will be deleted thus this code block will stop being run.
In regular if/else form that would go something like this
if (this.aV) {
this._alpha += this.aV/speed;
} else {
this._alpha = value;
delete this.onEnterFrame;
}
- if (this.aV) {
- this._alpha += this.aV/speed;
- } else {
- this._alpha = value;
- delete this.onEnterFrame;
- }
I help this better clarifies for you joebert
