removeChild
Switching parents at runtime
This example comes from a conversation I had with Andy. You can actually do a lot of neat tricks by swapping parents, especially when you start rotating the parents.
package { import gs.TweenMax; import org.papervision3d.core.math.Matrix3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class SwitchingParentsAtRuntime extends BasicView { private var parent1:Sphere; private var parent2:Sphere; private var childSphere:Sphere; private var light:PointLight3D; public function SwitchingParentsAtRuntime() { var headerText:headerContainer = new headerContainer(); headerText.header.text = "Click a red sphere to set as parent"; addChild(headerText); viewport.interactive = true; light = new PointLight3D(); var parentMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); parentMaterial.interactive = true; var childMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0x00cc00); parent1 = new Sphere(parentMaterial, 300, 10, 10); parent1.x = -500; parent1.y = 500; parent1.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, objectPressHandler); parent1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler); parent1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler); parent2 = new Sphere(parentMaterial, 300, 10, 10); parent2.x = 500; parent2.y = -500; parent2.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, objectPressHandler); parent2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler); parent2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler); childSphere = new Sphere(childMaterial, 100, 10, 10); childSphere.name = "child"; scene.addChild(parent1); scene.addChild(parent2); parent1.addChild(childSphere); childSphere.x = 500; TweenMax.to(parent1, 2, {y:-500, yoyo:true}); TweenMax.to(parent2, 2, {y:500, yoyo:true}); startRendering(); } private function objectPressHandler(event:InteractiveScene3DEvent):void { var parentSphere:Sphere = Sphere(event.target); if(childSphere.parent == parentSphere) { //do nothing }else { var childSphereWorldMatrix:Matrix3D = childSphere.world; var inverse:Matrix3D = new Matrix3D(); var tempParentMatrix:Matrix3D = new Matrix3D(); inverse.calculateInverse(parentSphere.world); tempParentMatrix.calculateMultiply(inverse, childSphereWorldMatrix); childSphere.copyTransform(tempParentMatrix); //get the parent of the child to //remove the child from the parent :) childSphere.parent.removeChild(childSphere); parentSphere.addChild(childSphere); } } private function objectOverHandler(event:InteractiveScene3DEvent):void { viewport.buttonMode = true; } private function objectOutHandler(event:InteractiveScene3DEvent):void { viewport.buttonMode = false; } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- FDT Theme Designer
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
Recent Comments
- شقق للبيع في الاردن on Moving to johnlindquist.com
- Annakhan006 on Augmented Reality – Recursive Webcam
- Yarout on Augmented Reality – Recursive Webcam
- Vivon on about
- Josh @ Wall Stickers on Moving to johnlindquist.com
- list of lpn courses on SpringCamera3D and Driving a Car
- rn to bsn in montgomery al on archive
- PowerPoint Recovery on Eclipse Theme Designer Preview
- cheat mw3 on Test if a plane is within the view of the camera (aka testing if culled)
- Goa Hotels on Looking around the inside of a Sphere
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Archives
Preferred Video Tutorial Resolution
- 1024x768 (53%, 85 Votes)
- 1280x1024 (15%, 24 Votes)
- 1920x1080 (15%, 24 Votes)
- 800x600 (13%, 20 Votes)
- 480x320 (4%, 6 Votes)
- 640x480 (0%, 2 Votes)
Total Voters: 160


