How do I use it?
Copy the ReflectEffect.as file into the classpath of your Flash project (or the same directory as your FLA if you're not using classpaths).
In your code, create a new instance of the ReflectEffect class, passing it the display object that you want it to reflect, like so:
var reflect:ReflectEffect = new ReflectEffect(movieClipToReflect);
Create a new variable for your reflected object and add it to the stage (or wherever you like):
var reflectedDown:Bitmap = reflect.down(length, fade, offset, blur, alpha); reflectedDown.y = movieClipToReflect.y + movieClipToReflect.height; addChild( reflectedDown );
The functions reflect.down(), reflect.up(), reflect.left() and reflect.right() will return a Bitmap of your object reflected in that direction. (Only the "length" parameter is required, the rest are optional.) As you see, you've got a few interesting options.
I think "length" is clear. So let's take a look at "fade". For example, if you put 40 for length and 30 for fade, the reflection is going to end 10px behind the actual reflection. Or, if you'd like you can set 40 for length and 50 for fade. This will make the reflection go from an alpha of 1.0 to something like 0.2.
The next is very interesting: "offset". This basically moves your reflection up/down (or left/right) inside the Bitmap output. I use this option in the preview so that you can move your object around and see a Mac-like effect.
The last two parameters, "blur" and "alpha", are pretty clear -- take a look at the comments in the class for more info!
Enjoy, and let us know how you use this class :)
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.Update me weekly
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post