ActionScript 3 Reflection Class Source
**
UPDATE
This class has been updated and is available here:
http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html
**
Awhile back I had a lot of good feedback on my Reflect class for ActionScript 2 in Flash 8. Since today I got my hands on the Flash 9 Alpha I thought that it would be fitting to update the Reflect class to ActionScript 3. Obviously lots has changed so it was a very educational process. This class has been renamed Reflection and does not support animation yet - this was a quick test to see what it would take to port the class over. Below is the source and if you have Flash Player 9 installed you will also see an example below as well. In the example you will see two separate clips, one with a jpg in it and one with native Flash text in it. Let me know what you think! Also, how is everyone doing processing comparisons these days? I'd love to be able to test the performance differences between the classes.
For those of you without Flash Player 9 here is a screenie:

Here is the class:
UPDATE
This class has been updated and is available here:
http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html
**
Awhile back I had a lot of good feedback on my Reflect class for ActionScript 2 in Flash 8. Since today I got my hands on the Flash 9 Alpha I thought that it would be fitting to update the Reflect class to ActionScript 3. Obviously lots has changed so it was a very educational process. This class has been renamed Reflection and does not support animation yet - this was a quick test to see what it would take to port the class over. Below is the source and if you have Flash Player 9 installed you will also see an example below as well. In the example you will see two separate clips, one with a jpg in it and one with native Flash text in it. Let me know what you think! Also, how is everyone doing processing comparisons these days? I'd love to be able to test the performance differences between the classes.
For those of you without Flash Player 9 here is a screenie:

Here is the class:

Hi, this version doesn't work with flash 9 alpha, mind to get it working? it looks so nice. Thanks, Jadd.
Posted by
Anonymous |
1:13 PM
Hi this is a great package. But where can I get the AS2 class? Is it still available. Best
Posted by
ron |
8:50 AM
http://pixelfumes.blogspot.com/2005/10/reflection-class-20-now-for-download.html
Posted by
Sarge |
8:51 AM
i tried your class but i always seems to get the following error. when i run my as3.fla file. when i run check syntax no error occures.
1119: Access of possibly undefined property graphics through a reference with static type flash.display:DisplayObject.
i already imported grahpics a second time:
import flash.display.*
import flash.display.Graphics;
what could be the problem in this? and how come flash has problems with finding it's own classes?
Posted by
Kris |
6:04 AM
Kris, This article and code are a bit old school now - please try the newest version of this class on the Adobe website here: http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html
If that doesn't work for you let me know!
Posted by
Sarge |
7:35 AM
hi sarge,
i been working with papervision3d classes in AS3..i want to reflect planes in papervision...but it shows no reflection...
//code...................
import com.pixelfumes.reflect.*;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
var container:MovieClip=new MovieClip();
container.x=stage.stageWidth*0.5;
container.y=stage.stageHeight*0.5;
container.name="mc1";
addChild(container);
this.frameRate=40;
var scene:Scene3D=new MovieScene3D(container);
var camera:Camera3D=new Camera3D();
camera.zoom=10;
//star making planes...
//create material-by attaching bitmap using BitmapAssetMaterial
var bam:BitmapAssetMaterial=new BitmapAssetMaterial("FlashIcon");
//by default material applied to one side of object(here plane);
bam.oneSide=false;
bam.smooth=true;
for (var i:int=0; i<1; i++) {
//new Plane(material,height, width,triangle num,triangle num)---triangle num to control quality
var p:Plane=new Plane(bam,150,75,2,2);
p.x=50*i;
p.y=40;
p.z=40*i;
p.rotationY=45;
scene.addChild(p);
var container2:Sprite = p.container;
}
scene.renderCamera(camera);
var mc1:Sprite = getChildByName("mc1") as Sprite;
var r1:Reflect = new Reflect({mc:mc1 , alpha:50, ratio:100,distance:0, updateTime:0, reflectionDropoff:1});
this.addEventListener(Event.ENTER_FRAME,render);
function render(e:Event) {
scene.renderCamera(camera);
}
//code ends here...............
if u have touch in it please help me thank uuuuuuuuuu
http://sara-intop.blogspot.com is my blog thanks...
Posted by
Saravanan |
6:08 AM
Hey,
Great Class! - thanks
It works great locally on my machine..however, when I put it online I get a security sandbox error that looks like this:
SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: http://aftertheanthems.com/mainVideo.swf cannot access http://static.blip.tv/Aftertheanthems-AfterTheAnthemsAlbumTrailer959-16.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::BitmapData/draw()
at com.pixelfumes.reflect::Reflect/::update()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at ()
at flash.utils::SetIntervalTimer/flash.utils:SetIntervalTimer::onTimer()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
Does anyone know why this is?
Thanks
Phil
Posted by
Phil |
7:43 PM
Phil, that is because you cannot, without a cross-domain policy file, reflect (use the bitmapData.draw() method) on a video that is live or hosted on a different domain.
Posted by
Sarge |
8:17 PM
HI sarge,
is it possible to give reflection for masked area only..
import flash.display.MovieClip;
var A_mc:MovieClip=new MovieClip();
with (A_mc) {
graphics.beginFill(0xFF0000);
graphics.drawRect(0,0,300,100);
graphics.endFill();
x=100
y=100
}
addChild(A_mc);
var B_mc:MovieClip=new MovieClip();
with (B_mc) {
graphics.beginFill(0xFFFF00);
graphics.drawRect(0,0,300,100);
graphics.endFill();
x=120
y=120
}
addChild(B_mc);
Posted by
Saravanan |
2:15 AM
Saravanan,
Sometimes the reflect has problems with masks. I haven't had the time to work on masked clips - occasionally it is because the clip height is higher than you think because the masked item actually returns the height of itself vs the height of the mask - that pushes the reflection -does that make sense?
Posted by
Sarge |
12:18 PM
Phil I have make some solution for SecurityError: Error #2122: Security sandbox violation, visit my blog at http://theflashblog-bg.com/index.php?p=40 for more information.
Posted by
dfm |
5:15 PM
This works great in flash but when I embed the swf in html using the swfObject the reflection does not show up???
Posted by
Nik37 |
4:20 AM
Impressive this IT world!! Really cool!!
Posted by
jdm |
12:51 PM
Hi -
As everybody, I would like to thank you about this "class".
Now, ahemmmm…
When I call it into my own .FLA, I got this error:
ReferenceError: Error #1065: Variable Reflect is not defined.
at untitled_fla::MainTimeline/frame1()
Do you know why?
Thank you, have a nice day…
- Dimitri
Posted by
dimitri_c |
2:43 PM
Nice class man.
One question, I have an array of images(movieclips) which all have instances of the reflect class.
How do I remove all of the reflections in the array properly. I am using imgArray[i].removeChildAt(1); at the moment but it seems to make everything run slow because I have called the destroy() method.
How do I call that method for every movieclip in the array?
Thanks
Posted by
Nick |
7:43 PM
Nick, sounds like you are going about it the right way. Loop through the items in the array and call the destroy method on each. Also, are you using the latest version of the class from http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html?
-Ben
Posted by
Ben |
10:02 AM
Hi,
I am using your reflection class in one of my projects.
When i apply reflection on a movie clip, the reflection is overlapping a button below it in the same flash movie. The overlapping part is fully transparent but it s there, as I am not able to click on the button. I can only click on lower part of the button. I tried using the setBounds() method but then reflection is gone. Can you please let me know what might be ausing this problem?
Posted by
Rahul Joshi |
3:01 AM
Set the clip being reflected to mouseChildren = false and mouseEnabled = false. If this isn't viable for you, you can mod the class to apply those properties to the Reflection. Also, make sure you are using the newest version of this class here: http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html
Posted by
Ben |
8:43 AM