Masking a 3D Container in AS3 (FP10)
February 16th, 2009 • ActionScript, Flash
»Easily transform and animate any display object through 3D space while retaining full interactivity.« That’s one of the key features in FlashPlayer 10 according to Adobe. You might think: "Woohoo, that’s fantastic" … so did I. But actually this is not completely true.
I was trying to set a mask or the scrollRect-property of a Sprite and as long as you don’t use one of the new 3D properties (rotationX, rotationY, rotationZ, …) this works as supposed. After changing one of the 3D properties and therefore using the new 3D API the mask will not work anymore. Of course this is not mentioned in the FP10 AS3 reference.
8 Responses (Add Your Comment)
-
İhsan March 5, 2009at 9:45 pm
-
Peter Strømberg April 7, 2009at 11:51 pm
THat dosn’t appear to work for masks
-
Gianluca July 11, 2009at 12:44 am
I have the same problem how do you solve it?
-
hmmm. If you want to window-mask a 3d object, lets say delimit the area where a 3d animation is visible, this wont work. The mask itself is a 2d square above everything. We dont want this 3d transformed in any way, just the object masked by it to be so and only show through the mask. This scenario is not covered in the above solution.
Well, that issue was a total deception for me too. But there is a workaround.
When you define a sprite for 3d properties, define another child sprite in it for 2d rendering. Do all coordinate and 3d operations in the parent and 2d rendering in the child. That worked perfect[including scrollRect(in child)] for me.
Example:
in the fla file actionscript:
var p: Sprite = new Sprite();
var c: Sprite = new Sprite();
p.addChild(c);
p.x = 100;
p.y = 100;
p.z = 10; // for instance
c.graphics.beginFill(0×0000F0);
c.graphics.drawRoundRect(0,0,50,100,5);
c.graphics.endFill();
c.scrollRect = new Rectangle(0,0,50,50);
//remove remarks for
//p.rotationX=45;// testing with these
//p.rotationZ=45;// to see clipping
//is actually done,
addChild(p);
// this will render a square instead of rectangle in 3d
I hope this helps.