Using the viewport for interactivity
This example shows an alternate way of allowing you to click on 3d objects. Since every 3d object is rendered to the viewport, you can just add a mouse click event listener to the viewport directly. Of course, this limits you to having only one click action for every 3d object.
My next post will show how to create individual viewport layers for each object.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package { import flash.events.MouseEvent; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="900", height="480", backgroundColor="#000000", frameRate="31")] public class AlternateInteractivity extends BasicView { public function AlternateInteractivity() { super(900, 480, false, false); var n:int = 30; for(var i:int = 0; i < n; i++) { var color:Number = Math.random() * 0xffffff; var material:MaterialObject3D = new ColorMaterial(color); var sphere:Sphere = new Sphere(material); sphere.x = Math.random() * 3000 - 1500; sphere.y = Math.random() * 3000 - 1500; sphere.z = Math.random() * 3000; scene.addChild(sphere); } singleRender(); //shows hand cursor when rolling over spheres viewport.buttonMode = true; //allows you to click on any of the spheres //since they're just bitmaps in the viewport viewport.addEventListener(MouseEvent.CLICK, viewport_clickHandler); } private function viewport_clickHandler(event:MouseEvent):void { for each(var sphere:Sphere in scene.children) { sphere.x = Math.random() * 3000 - 1500; sphere.y = Math.random() * 3000 - 1500; sphere.z = Math.random() * 3000; } singleRender(); } } } |
-
Aleks
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
- 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
- MorphController – Mighty Morphing Papervision3D
Recent Comments
- reverse cell phone lookup on Augmented Reality – Recursive Webcam
- Register Domain Name on Augmented Reality – Recursive Webcam
- Katie on Augmented Reality – Recursive Webcam
- software akuntansi terbaik on Back in the saddle
- loan rates on Augmented Reality – Recursive Webcam
- loan rates on Looking around the inside of a Sphere
- reverse phone lookup on Looking around the inside of a Sphere
- Oidhreachta on The Spotlight Effect (Dimming the unselected)
- Hosting company on archive
- aanbae on Back in the saddle
Categories
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


