« BitmapData and Matrix weirdness
» Flex CoverFlow Component updated

Actionscript 3, Adobe Flash, Adobe Flex 2, Away3D

Flex Reflections Component and Actionscript Class

05.28.08 | 15 Comments

There are a lot of Reflection classes around, but I always enjoy writing my own. I had a special purpose in mind with writing this one; I wanted to create a reflection of a displayObject as a BitmapData, so I could use it as a Material in Away3D or any other actionscript 3D API. One thing led to another, and before I knew I was writing a Reflection Flex component as well.

So the idea is that there are two flavors to this Reflection classes:

  • The Actionscript-only way to create a Reflection
  • The MXML-only way to create a Reflection

I also wanted to be able to create a reflection of a video or any other moving object. Check the example to see it in action.

An image with reflection using Actionscript and or Flex

The Actionscript-only way to create a Reflection

I’ve created this one so you can create reflections in Flash or in any Actionscript project. I’m going to use this to create reflection BitmapData’s to use in Away3D. Here’s how you use it:

1
var reflection:Reflect = new Reflect(this.image1 as Sprite, 0.4, 100, true, Reflect.BOTTOM, 0);

The constructor arguments are:

  • The sprite to reflect
  • the alpha value
  • the ratio value
  • a boolean to tell if it should be added as a child to the target sprite
  • the direction of the reflection
  • the updateTime, this one is set to 0, so it doesn’t periodically update the reflection

See the example here
See the sourcecode here

The MXML-only way to create a Reflection

The component version uses exactly the same arguments as the Actionscript class. All properties (except for the updateTime) are bindable, so you can alter the alpha, ratio, etc at runtime.

1
 

See the example here
See the sourcecode here

There’s one problem with reflecting dynamic textfields. I’m using a Matrix to create the Flipped BitmapData. Unfortunately the scale and translate methods of the Matrix mess up the rendering of dynamic textfields, but hey, who would want to reflect a boring textfield or dateChooser ;-)
I’ve written a post about this problem, you can read it here. I know the solution to this problem; Use a Bitmap and set the scaleY property, but this will only flip the Bitmap, the BitmapData is still not flipped, and as I mentioned before, this was all to do about the Flipped and reflected BitmapData.

15 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« BitmapData and Matrix weirdness
» Flex CoverFlow Component updated