Running PaperVision3d 2.0 Example in Flex3
I’ve been using Flash library clips in my Flex apps for a while now, using Embed in AS3. This is just an example of how to apply that approach to a pre-existing Flash Actionscript3 project (like the one in the PV3 2 repository, Mouse3D).
Really, it’s not that difficult (once you figure out the steps):
1) import the latest PV3D libraries
2) import the Mouse3D .fla
3) create a Canvas.as class file to hold the Canvas MC.
4) create a Main.as class file to hold the core code from the sample
5) create a .mxml container app to hold all the AS code

Code samples:
// Canvas.as by Ben Honda Rottler package { import flash.display.MovieClip; [Embed(source="/Mouse3D.swf", symbol="Canvas")] public class Canvas extends MovieClip { public var surface : MovieClip; public function Canvas() { } } }
The Canvas Class is essentially a holder which pulls in the MC from the .swf library. You can extend this as well, which is very useful in practice. Next, the MXML container:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" applicationComplete="init()" backgroundGradientColors="[#FFFFFF, #FFFFFF]" backgroundColor="#FFFFFF" frameRate="60"> <mx:Script> public function init() : void { var main : Main = new Main(this.holder); } </mx:Script> <mx:Canvas width="640" height="480" id="holder" top="20" left="60"></mx:Canvas> </mx:Application>
I won’t repost all of the Main.as code, as it’s mostly the same as what’s in the example, except for a few tweaks to add the object to the Display stack. Also note that Main itself needs to be changed from a MovieClip to a UIComponent. Enjoy.
public class Main extends UIComponent { // ___________________________________________________________________ 3D vars public var viewport :Viewport3D; public var scene :Scene3D; public var camera :Camera3D; public var ball :Sphere; public var gismo :Cube; public var renderer :BasicRenderEngine; public var mouse3D :Mouse3D; public var vMouse :VirtualMouse; public var surface :Sprite; public var ref : UIComponent; public function Main(tref : UIComponent) { ref = tref; init(); } public function init():void { ref.addChild(this); init3D(); addEventListener( Event.ENTER_FRAME, loop ); }
