Tutorial – Creating the reflection of an image dynamically in AS3

6 actionscript,as3,as3 tutorials,flash,work  |   July 18, 2007  |     1578

You’ve seen it everywhere, even in the new iTunes. Basically the idea is to create a reflection of an image, as if the surface it is standing on was mirror-like.

sample reflection

I’ve managed to hack away some code using the BitmapData, Bitmap and Sprite classes. This is probably not an efficient way to do things, especially the changeAlpha function which adapts the negative color values (why do I get that?) for each pixel.

_art is a Sprite containing the image we want to create the reflection of; in my example _art has been scaled by fixing it’s width and height dynamically, therefore we need to take that into consideration when drawing it’s content into a BitmapData object

_artReflection is a Sprite which will contain the reflection

Here we go:

Voilà. Post your comments or questions! Or even better, improve the efficiency of my code!

  • May 12, 2008 at 8:50 am


    and thanks for the useful script!
    How do you create a Sprite from an image loaded dynamically? Could you post some fast code about that?


  • September 9, 2008 at 7:59 am


    useful !

  • March 21, 2009 at 2:06 am


    link to source if you’d like help with your code, mate.


  • March 23, 2009 at 12:37 am


    if you cast as uint you won’t get negative values…

    var alphaOffset:uint = color>>> 24 & 0xFF;
    var redOffset:uint = color>>> 16 & 0xFF;
    var greenOffset:uint = color >>> 8 & 0xFF;
    var blueOffset:uint = color & 0xFF;
    //i = (x ^ (x >> 31)) – (x >> 31); this is the same as math.abs …also ternary below
    greenOffset=(greenOffset <0)?(-greenOffset):(greenOffset);
    redOffset=(redOffset <0)?(-redOffset):(redOffset);
    blueOffset=(blueOffset <0)?(-blueOffset):(blueOffset);

    thanks again, this is fun to play with…

  • October 25, 2009 at 12:09 pm


    That’s pretty neat stuff, definitely fun to play with. As you said, probably not the most efficient, but it can be fixed up.

  • March 30, 2010 at 8:08 am

    sprite mk

    […] least come with the addition of online leaderboards. … Mail (will not be published) (required) …intense creativity Tutorial – Creating the reflection of an …I’ve managed to hack away some code using the BitmapData, Bitmap and Sprite classes. … _art is a […]

Leave a Reply