Experiment 3 - When PerspectiveProjection is assigned to an Object Contained in a 3D Object

The code for the applet below differes from the previous examples as follows. container1 and container2 are left in place but the PerspectiveProjection instances, pp1, pp2, are asigned to children of container1 and container2 - holder1 and holder2 - rather than to container1 and container2. The Make3D button tests what happens when container1 becomes a 3D object. The Remove button removes custom PerspectiveProjection assignments.

Changes in the Code

For clearer effects, we vary in this applet values of the fieldOfView property of pp1, pp2, and this.transform.perspectiveProjection. We also assign pp1 and pp2 to holder1 and holder2. The file in the pp.zip corresponding to thes experiment is pp_show3.fla.

var pp1:PerspectiveProjection=new PerspectiveProjection();

pp1.fieldOfView=140;

pp1.projectionCenter=new Point(0,0);

var pp2:PerspectiveProjection=new PerspectiveProjection();

pp2.fieldOfView=100;

pp2.projectionCenter=new Point(0,0);

holder1.transform.perspectiveProjection=pp1;

holder2.transform.perspectiveProjection=pp2;

this.transform.perspectiveProjection.fieldOfView=80;

btn3D changes container1 into a 3D object and btn2D which makes container2 back into a 2D object.

btn3D.addEventListener(MouseEvent.CLICK,btn3DClick);

 

function btn3DClick(e:MouseEvent):void {

container1.z=0;

//After the z coordinate is assigned, container1 becomes a 3D object.

}

 

btn2D.addEventListener(MouseEvent.CLICK,btn2DClick);

 

function btn2DClick(e:MouseEvent):void {

container1.transform.matrix3D=null;

//container1 is now a 2D object as its matrix3D is null.

container1.x=100;

container1.y=120;

}

As before, Remove and Restore buttons remove custom PerspectiveProjection assignments pp1 from the first. Once the assignments are removed, holder1 and holder2 inherit perspective projection settings from the root object.

btnRemove.addEventListener(MouseEvent.CLICK,btnRemoveClick);

 

function btnRemoveClick(e:MouseEvent):void {

holder1.transform.perspectiveProjection=null;

holder2.transform.perspectiveProjection=null;

}

 

btnRestore.addEventListener(MouseEvent.CLICK,btnRestoreClick);

 

function btnRestoreClick(e:MouseEvent):void {

holder1.transform.perspectiveProjection=pp1;

holder2.transform.perspectiveProjection=pp2;

}

When container1 which contains holder1 changes into a 3D object, ALL PespectiveProjection settings of pp1 are removed, including fieldOfView. Recall, pp1 is assigned to holder1 - a child of container1. A child of a 3D object which does not have a PerspectiveProjection object assigned to it looses its custom perpective projection assignments.

Download

  • Download all the source files corresponding to this tutorial: pp.zip

On the next page we show the simplest but not the most flexible way of assigning perspective projection to display objects.

Back to Flash CS4 Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.