3. Creating a Papervision Base Template
The first thing that you should do when creating a Papervision 3D project is to create a "Base Class" which will serve as a template to speed up the start of each papervision project you attempt.
1) Create a new FlashDevelop Project
Open up FlashDevelop. On the start page, click on the New: Project... Under the Recent Projects Window.

The New Project dialog box will appear. Under Actionscript 3, click Empty Project. Type a name into the Name textbox, and tick the box labelled "Create Directory for Project".
Click OK to close the dialog box. You will now see your project under the Project window. We need to add a source file to the project.
The first thing you need to do to your project is to import the papervision source so that your program can use it. From the menu at the top, choose Project, then Settings.
The Project settings dialog box will appear. Click on the Classpaths tab and click Add Classpath.
You now need to browse to the folder in which you downloaded the GreatWhite source code in tutorial number 2. Select the greatwhite folder (It should contain directories called org, fl and com) and click OK.
You should now have an icon which looks like a Lego Brick containing the GreatWhite source code under your project.

You now need to make a script to be executed when your program runs. Right click on your project in the project tree and goto Add > New Class.

Name the new class PaperBase.as and click OK. You will now have the Main.as file open in your editor. The code will look like this:
-
/**
-
* ...
-
* @author Default
-
* @version 0.1
-
*/
-
-
package {
-
-
public class PaperBase {
-
-
public function PaperBase() {
-
-
}
-
-
}
-
-
}
This is a blank class. Firstly, we need to make this class compile when we run the project. To do this, right click on Main.as under the project tree and select "Always Compile".
We also need to specify the output SWF location. To do this, from the Project menu, select Properties.
On the Output tab under General, you'll see an input box labeled "Output File". Click Browse and choose where to place the output file.
Now, change the source code so that it looks this (Comments in the code explain each step of the way):
-
package {
-
// These lines make differant 'pieces' available in your code.
-
import flash.display.Sprite; // To extend this class
-
import flash.events.Event; // To work out when a frame is entered.
-
-
import org.papervision3d.view.Viewport3D; // We need a viewport
-
import org.papervision3d.cameras.*; // Import all types of camera
-
import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
-
import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
-
-
public class PaperBase extends Sprite { //Must be "extends Sprite"
-
-
public var viewport:Viewport3D; // The Viewport
-
public var renderer:BasicRenderEngine; // Rendering engine
-
// -- Scenes -- //
-
public var default_scene:Scene3D; // A Scene
-
// -- Cameras --//
-
public var default_camera:Camera3D; // A Camera
-
-
public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
-
initPapervision(vpWidth, vpHeight); // Initialise papervision
-
init3d(); // Initialise the 3d stuff..
-
init2d(); // Initialise the interface..
-
initEvents(); // Set up any event listeners..
-
}
-
-
protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
-
// Here is where we initialise everything we need to
-
// render a papervision scene.
-
viewport = new Viewport3D(vpWidth, vpHeight);
-
// The viewport is the object added to the flash scene.
-
// You 'look at' the papervision scene through the viewport
-
// window, which is placed on the flash stage.
-
addChild(viewport); // Add the viewport to the stage.
-
// Initialise the rendering engine.
-
renderer = new BasicRenderEngine();
-
// -- Initialise the Scenes -- //
-
default_scene = new Scene3D();
-
// -- Initialise the Cameras -- //
-
default_camera = new Camera3D(); // The argument passed to the camera
-
// is the object that it should look at. I've passed the scene object
-
// so that the camera is always pointing at the centre of the scene.
-
}
-
-
protected function init3d():void {
-
// This function should hold all of the stages needed
-
// to initialise everything used for papervision.
-
// Models, materials, cameras etc.
-
}
-
-
protected function init2d():void {
-
// This function should create all of the 2d items
-
// that will be overlayed on your papervision project.
-
// User interfaces, Heads up displays etc.
-
}
-
-
protected function initEvents():void {
-
// This function makes the onFrame function get called for
-
// every frame.
-
addEventListener(Event.ENTER_FRAME, onEnterFrame);
-
// This line of code makes the onEnterFrame function get
-
// called when every frame is entered.
-
}
-
-
protected function processFrame():void {
-
// Process any movement or animation here.
-
}
-
-
protected function onEnterFrame( ThisEvent:Event ):void {
-
//We need to render the scene and update anything here.
-
processFrame();
-
renderer.renderScene(default_scene, default_camera, viewport);
-
}
-
-
}
-
-
}
This is heavily commented, so it should explain everything that's happening.
When you run the project, you'll just see a blank screen, this is expected because you haven't added anything to the scene yet.
You can download the source file with the code comments or without using the links below:
This file will now be used as the basis of any papervision projects that you do, and with very few lines added to that code, you can get really good results.
*EDIT*
Updated 20th August 2008, now works with the GreatWhite codebase changes
If you enjoyed this post, feel free to Buy Me a Beer!




"Without Comments" version still has one line of comment in it.
Nice tutorials by the way.
I did everything exaclty as above and i get this:
Running process: C:\Users\Administrator\AppData\Local\FlashDevelop\Tools\fdbuild\fdbuild.exe "C:\Users\Administrator\Documents\PaperBase\PaperBase.as3proj" -ipc 642d8fdc-bd5c-469a-8cb8-a0ada52fb3cc -compiler "C:\FlexSDK" -library "C:\Users\Administrator\AppData\Local\FlashDevelop\Library" -cp "C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\Classes" -cp "C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Component Source\ActionScript 3.0\User Interface"
HINT: Improve your build speed when compiling in FlashDevelop3 by placing the Adobe Flex Compiler Shell in your Flex2 bin path.
Building PaperBase
mxmlc -load-config+=obj\PaperBaseConfig.xml -debug=true -benchmark=false -o obj\PaperBase633388734994054445
Error loading: C:\Program Files\Java\jre1.6.0_04\bin\client\jvm.dll
Build halted with errors (mxmlc).
Done (1)
@Pimm,
Thanks but that comment has been left in intentionally. It's just there because it would be an empty function if it wasn't, just looks neater that's all
@David,
Looks like you've got a problem with your Java Runtime Environment. Try reinstalling or updating it. You can download the version of the JRE that I use here: http://filehippo.com/download_java_runtime/
Hope this helps!
It works Thanks!!!
Great Idea. Thanks, I'll use this now.
I am looking for this same information but for Flex Development (mac based)... took a look at FlashDevelop, snazzy. Any suggestions?
Running process: C:\Documents and Settings\ratm\Local Settings\Data aplikací\FlashDevelop\Tools\fdbuild\fdbuild.exe "E:\--{ FLASH 3 }--\frenchtouch\PaperBase.as3proj" -ipc 70700430-2d73-4b63-8e4c-7ae80713fe4b -compiler "E:\--{ FLASH 3 }--\flexsdk" -library "C:\Documents and Settings\ratm\Local Settings\Data aplikací\FlashDevelop\Library"
HINT: Improve your build speed when compiling in FlashDevelop3 by placing the Adobe Flex Compiler Shell in your Flex2 bin path.
Building PaperBase
mxmlc -load-config+=obj\PaperBaseConfig.xml -debug=true -benchmark=false -o obj\PaperBase633403583922343750
defaults: Error: unable to open 'E:\----\flexsdk\frameworks/flex-config.xml'
Build halted with errors (mxmlc).
Done (1)
C:\Papervision\Base\PaperBase\PaperBase.as(15): col: 31 Error: Type was not found or was not a compile-time constant: Camera3D.
also
C:\Papervision\Base\PaperBase\PaperBase.as(35): col: 25 Error: Call to a possibly undefined method Camera3D.
I just copied your final code.... And went through the set up once again... any suggestions?
Running process: "lots of text that isn't necessary to write"
Building New-Project
mxmlc -load-config+=obj\New-ProjectConfig.xml -debug=true -benchmark=false -o obj\New-Project633407533560000000
Error loading: C:\Program\Java\jre1.6.0_05\bin\client\jvm.dll
Build halted with errors (mxmlc).
Done (1)
Getting the same error as David did, I've reinstalled Java three times to make it work but nothing helps (yes, I used the version that you linked). Any suggestions?
Thanks in advance
-Joxe
You are aware that BasicView in the papervision3D repository has exactly this function ?
protected var log :XrayLog = new XrayLog();
its in org/papervision3d/utils/InteractiveSceneManager.as
that line is causing an error, its not imported seemingly anywhere, do I have an up to date set of libraries ?
Hi Ralph,
Yeah I'm aware of the BasicView class, but it doesn't allow as much flexibility and it would require things like the event listeners to be added for every project. I decided to use this for a couple of reasons, 1 - It's a bit confusing having only half of the basic stuff already done for you, and 2 - Creating my own base class will help people understand the inner workings of the engine.
@ mojito, You can safely remove all occurences of the XrayLog thing from your project. You'll most likely never use it, it was just used by the developers to help with debugging.
-Luke
Hello. I am new to this but getting the following error. FlashDevelop worked fine the first time I ran it but now I get the error. I reinstalled another time and still the same. Help
jwhite@mediatechinc.com
ould not find file 'C:\Documents and Settings\ALX\Local Settings\Application Data\FlashDevelop\Settings\MainMenu.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at PluginCore.Helpers.XmlHelper.LoadXmlDocument(String file)
This error ocurred when i try to build project
"...
Loading configuration file E:\paper\ExtrudeImage\obj\extrudeConfig.xml
E:\paper\ExtrudeImage\obj\extrudeConfig.xml(13): Error: unable to open 'C:\Documents and Settings\Marcio\Local Settings\Application Data\FlashDevelop\Library\AS3\classes'
Build halted with errors (mxmlc).
Done (1)"
Why this? And how can fix this?
Still getting the following error. I reinstalled a few times. It just appear the xml file is missing from the folder. Windows XP is my OS. Any help would be great.
could not find file 'C:\Documents and Settings\ALX\Local Settings\Application Data\FlashDevelop\Settings\MainMenu.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at PluginCore.Helpers.XmlHelper.LoadXmlDocument(String file)
Just FYI, Figured out the Viewport3D error.
My suspicion is that folks are downloading Papervision from papervision.org and aren't getting the GreatWhite build.
The papervision archive does not include some of the classes within GreatWhite so you will see the Viewport errors.
Cheers,
-S
I am totally new to all of this and can't seem to figure out why these import statements are failing. I have followed the instructions above for downloading the GreatWhite files and pointing the ClassPath to this folder on my computer but the following errors are showing:
MxmlcShell command: -o;C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.swf;--;C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.as
Loading configuration file C:\Documents and Settings\mark\Desktop\actionscript_pv3d\flex2_sdk_hf1\frameworks\flex-config.xml
C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.as(5): col: 32 Error: Definition org.papervision3d.view:Viewport3D could not be found.
Done(4)
import org.papervision3d.view.Viewport3D; // We need a viewport
^
C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.as(6): col: 35 Error: Definition org.papervision3d.cameras could not be found.
import org.papervision3d.cameras.*; // Import all types of camera
^
C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.as(7): col: 34 Error: Definition org.papervision3d.scenes:Scene3D could not be found.
import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
^
C:\Documents and Settings\mark\Desktop\actionscript_pv3d\my_project\PaperBase\PaperBase.as(8): col: 34 Error: Definition org.papervision3d.render:BasicRenderEngine could not be found.
import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
^
Genial! Me ha servido de gran ayuda.
Great! It was a big help!
: )
You are been read by southamericans, in this case from Uruguay.
smoov as far as i know...
your import classes arent at the right folder for flash.
so check them
hope this fix your prob.
cheers
I'm getting compilation error even with non-strict compile mode:
Location:
FreeCamera3D.as, Line 91
Description:
1023: Incompatible override.
I am having the same issue as sm0o0v.
C:\ppv3d\3dtest\PaperBase.as(19): col: 23 Error: Type was not found or was not a compile-time constant: Viewport3D.
C:\ppv3d\3dtest\PaperBase.as(20): col: 23 Error: Type was not found or was not a compile-time constant: BasicRenderEngine.
C:\ppv3d\3dtest\PaperBase.as(22): col: 28 Error: Type was not found or was not a compile-time constant: Scene3D.
C:\ppv3d\3dtest\PaperBase.as(24): col: 29 Error: Type was not found or was not a compile-time constant: Camera3D.
C:\ppv3d\3dtest\PaperBase.as(36): col: 19 Error: Call to a possibly undefined method Viewport3D.
C:\ppv3d\3dtest\PaperBase.as(42): col: 19 Error: Call to a possibly undefined method BasicRenderEngine.
C:\ppv3d\3dtest\PaperBase.as(44): col: 24 Error: Call to a possibly undefined method Scene3D.
C:\ppv3d\3dtest\PaperBase.as(46): col: 25 Error: Call to a possibly undefined method Camera3D.
C:\ppv3d\3dtest\PaperBase.as(12): col: 32 Error: Definition org.papervision3d.view:Viewport3D could not be found.
C:\ppv3d\3dtest\PaperBase.as(13): col: 35 Error: Definition org.papervision3d.cameras could not be found.
C:\ppv3d\3dtest\PaperBase.as(14): col: 34 Error: Definition org.papervision3d.scenes:Scene3D could not be found.
C:\ppv3d\3dtest\PaperBase.as(15): col: 34 Error: Definition org.papervision3d.render:BasicRenderEngine could not be found.
I originally had the GreatWhite folder on another hard drive so I moved it back locally and put it on the C:\Flash Repository\GreatWhite
Any ideas on where I should be putting it or what I may be doing wrong?
Alright. Figured out I wasn't calling the class in my FLA.
Hey i dont have a main.as here
i'm glad..., it's working properly
Even though it's a blank one i feel really happy
So how does this work exactly? I do the steps above and then I can just open up Flash CS3 and make a new actionscript file and the base class will already be recognized?
Do I have to have the PaperBase.as file in my Actionscript 3.0 settings?
Is Flash Develop a actionscript editor?
I came to find this page after hitting this error message within Flash CS3:
Papervision error Type was not found or was not a compile-time constant: Viewport3D, while doing the "PV3D Intro - Hello World (I)" tutorial over at madverticies.com which was a recommended tutorial site by papervision.
Pardom my ignorance and thanks for your time and consideration.
Peace and Love,
Mikeumus.
I had the same problem as smoov. Fixed it by removing "" from project classpath which was first in the list. Using the Global Classpath also worked.
Hi guys, I'm having trouble to run the blank example. I think it might have to do with languages. When I run the project, I have this error:
C:\proyectos\scm-medialab\test\as3_projects\PaperBaseOk\obj\PaperBaseOkConfig.xml(13): Error: unable to open 'C:\Documents and Settings\Jesús\Configuración local\Datos de programa\FlashDevelop\Library\AS3\classes'
As you can see, there are some odd characters there (they correspond to the words "Jesús" and "Configuración"). Is there a way to configure FlashDevelop, so that I can put those libraries in another directory?
Thanks a lot.
Hi, I just made your base template and I am getting these errors...
Any idea...
Running process: C:\Documents and Settings\ASHLEY\Local Settings\Application Data\FlashDevelop\Tools\fdbuild\fdbuild.exe "F:\Ashley\Projects\Islandape 2008\is2008\islandape\islandape.as2proj" -ipc 380b940d-c898-4f49-a1c4-f650da409432 -compiler "C:\Documents and Settings\ASHLEY\Local Settings\Application Data\FlashDevelop\tools\mtasc" -library "C:\Documents and Settings\ASHLEY\Local Settings\Application Data\FlashDevelop\Library" -cp "C:\Documents and Settings\ASHLEY\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Classes"
Building islandape
Main entry point not found
Build halted with errors (mtasc).
Done (1)
Ashley
Para majadero:
http://blog.sergioalvarez.net/flashdevelop-30-beta/
Allì està la respuesta al problema
I could be stupid here, but I am getting this error when I compile. What could be wrong? Its getting stuck right on the first line
C:\Documents and Settings\user\My Documents\PaperBase/PaperBase.as:1: characters 0-7 : parse error Unexpected package
Hmm... got it. I created an AS2 project I guess. There you go
When i run the project i get this at my output box:
AscShell command: C:\Documents and Settings\kkkklk\Bureaublad\Nieuwe map (5)\Project interactive\PaperBase.as
Done(0)
I am trying to run this on a mac with Flash CS3.
I get these two compiler errors.
I did download the current base class.
Warning: 1090: Migration issue: The onPress event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseDown', callback_handler).
Sorry mate, could you tell us which version of Papervision3D your PaperBase is designed to work with? It doesnt seem to work with PaperVision 1.5.
Thanks mate
[...] Extremely helpful base template that sets up all the basic elements that you can easily build [...]
hello get following error : unexected package paperbase.as anyone know how to fix this
I get this error for Viewport3D.as:
Hey, can't post comment
I keep on getting this error for Viewport3D.as:
Hey what's wrong? everything after the first line doesn't get posted
Today I got the latest version from scratch, and the errors are gone. Good!
@Scott
some of you guys don't read from the beginning he tells you its not PV 1.5 you use, he has a big download image on the front page telling where to download the 2.0, he gives you tutorials on the very first tutorial on where to get it..
now i'm no different the average impatient guy, but i'm sure he does get a bit annoyed at people who fail to pay attention.. go from tut 1 and get the resources he mentions.
btw.. followed the instructions, although i'm using flashDevelop 3 beta 7 it doesn't show a main.as, i ignored creating it, and just continued with paperBase.as, and it worked.. thank you
@AdrianLMS
I am also having problems with FreeCamera3D...
Error: Type was not found or was not a compile-time constant: FreeCamera3D.
Error: Call to a possibly undefined method FreeCamera3D.
I did get this to work with the PaperBase.as supplied in this tutorial but not the newest version linked to on the left sidebar.
Dood.... you rule. Thank you.
Hi Luke
I tried the tutorial, but I´m getting the error when building for the first time and I´m not getting not even the blank screen.
the error I´m getting is:
D:\Trabalhos\Tutoriais_PV3D\PaperBase\obj\PaperBaseConfig.xml(12): Error: unable to open 'C:\Documents and Settings\FELIPE\Configurações locais\Dados de aplicativos\FlashDevelop\Library\AS3\classes'
Don´t know how to fix it. Could you please give some hint?
Thanks a lot!
hola necesito ayuda...
hello i need help .....
when i like to test proyect appert a error :
"
C:\Documents and Settings\web\Mis documentos\Prueba 3d\Prueba\obj\PruebaConfig.xml(13): Error: unable to open 'C:\Documents and Settings\web\Configuración local\Datos de programa\FlashDevelop\Library\AS3\classes'
"
porfavor ayuda.. gracias d antemano.
pleas help!!! thanks a lot!...