What is BasicView?
I use BasicView in all of my examples. This post explains why:
1. BasicView is a Sprite
Every ActionScript 3 project requires a “document class“. Since BasicView subclasses Sprite, you can extend BasicView to create your document class:
public class MyAwesomeDocumentClass extends BasicView
*note – You’ve probably heard the terms subclass, inherits, inheritance, extends, or others before. All those terms just mean you take advantage of the variables and functions of a specific class by writing another class that extends it. See Wikipedia’s Inheritance Page.
If you look at the docs, you’ll see the inheritance chain: BasicView->AbstractView->Sprite.
2. BasicView provides a viewport, scene, camera, and renderer
Every Papervision3D project requires a viewport, scene, camera, and renderer which are all classes in the Papervision3D library. If you don’t use BasicView, you have to do something like this:
package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.cameras.Camera3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class ImTooCoolForBasicView extends Sprite { private var viewport:Viewport3D; private var scene:Scene3D; private var camera:Camera3D; private var renderer:BasicRenderEngine; public function ImTooCoolForBasicView() { viewport = new Viewport3D(); addChild(viewport); scene = new Scene3D(); camera = new Camera3D(); renderer = new BasicRenderEngine(); var sphere:Sphere = new Sphere(); scene.addChild(sphere); addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function enterFrameHandler(event:Event):void { renderer.renderScene(scene, camera, viewport); } } }
Phew, that was a lot of work! Let’s look at what it looks like when you use BasicView:
package { import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class SmartGuysUseBasicView extends BasicView { public function SmartGuysUseBasicView() { var sphere:Sphere = new Sphere(); scene.addChild(sphere); startRendering(); } } }
Much better!
You probably also noticed that the second example has the handy little “startRendering()” function. StartRendering does the exact same thing as the addEventListener(Event.ENTER_FRAME, enterFrameHandler); line in the first example. The addEventListener line is hidden away in AbstractView:
Hiding functionality like that example is called encapsulation, but who really cares what it’s called as long as it makes it easier
3. What’s this override protected function onRenderTick thing in the examples?
onRenderTick is the enter frame event listener called when you use startRendering(). If you look at the code, you’ll notice onRenderTick is a protected function. Using protected allows you to change what the function does by overriding it.
*note – The keyword
protectedis one of ActionScript 3’s “accessibility modifiers”. You may be familiar with other keywords: public, private, internal, and final. To learn how each of these “control access” to functions, read through adobe’s keyword page: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/statements.html
By default, you just type startRendering(); and onRenderTick will just do the following each frame (you don’t have to type this out since it’s included in AbstractView):
renderer.renderScene(scene, camera, viewport);
You can change what onRenderTick does by writing it out like this:
override protected function onRenderTick(event:Event=null):void { sphere.yaw(1); renderer.renderScene(scene, camera, viewport); }
When overriding a function, remember that the parameters (event:Event=null) and the return type (void) have to remain exactly the same.
4. I get it! BasicView simply sets up what you need for Papervision3D!
Bingo! But that doesn’t mean you have to use BasicView. In fact, maybe your project requires multiple viewports or cameras and you’ll need to write out the code without BasicView. In the end, use what’s best for you.
As for me and my examples, I’ll be sticking with BasicView.
*final note – If you found how BasicView works interesting, I recommend reading up on the Template Pattern and the Facade Pattern.
-
As
-
Adam
-
TimQ
-
Chris
-
Kenton White
-
Michiel van der Ros
-
toffee
-
Paul Mayne
-
John Lindquist
-
John Lindquist
-
Thomas W
-
Paul Mayne
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

