Masking a 3D Container in AS3 (FP10)

»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)

  1. 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.

  2. actually I tried this as well and it didn’t work out for me. but I’ll definitely give that another shot … well, lets see if there is a happy end for my project, too. I’ll keep you posted about the result.

  3. Great I can’t believe it. I just put the code for the 3d transitions back in and it suddenly works. Strange somehow, I’m not sure what I was doing wrong in the first place, but hey … it’s working now. Thanks for pointing me to this workaround (even if the solution was already in my code) … just weird!!

  4. Peter Strømberg April 7, 2009
    at 11:51 pm

    THat dosn’t appear to work for masks

  5. Can you provide an example where it doesn’t work. in the beginning it didn’t work for me either and suddenly worked … so actually I’m using it now with a mask

  6. I have the same problem how do you solve it?

  7. You can do it like İhsan described above … throw your masked 2D Content in another Sprite and apply all the 3d operations to this container Sprite and everthing should be fine.

  8. 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.

Leave a Reply

Formatting: 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> <pre lang="" line="" escaped="">

Other Entries

About

Martin Rädlinger is an Interactive Developer & Designer. He specializes in interactive coding predominantly with ActionScript, but every new challenge is welcome. If you like his work feel free to get in touch with him. At the moment he's available for freelance work.

Contact

Martin Rädlinger
mail: mr [at] formatlos.de
web: www.formatlos.de
xing: Martin Rädlinger
linkedin: Martin Rädlinger
skype: martinraedlinger