Video in PaperVision 3D

Place video on to a polygon

Download Source Files

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

package  {
	/* PaperBase class included in Download 
	   created by  */
  	import PaperBase; 

	import org.papervision3d.materials.VideoStreamMaterial;  
    import org.papervision3d.objects.primitives.Plane;  		
    public class PaperVideo extends PaperBase {
        protected var sceneWidth:Number;      
        protected var sceneHeight:Number;
        private var videoPlane:Plane;   	// Plane that VideoStreamMaterial gets textured to
        private var videoStreamMaterial:VideoStreamMaterial;   // The type of texture that allows for video
        private var netConnection:NetConnection;
		private var video:Video;
		private var netStream:NetStream; 	// The NetStream class opens a one-way streaming connection between a Flash Player
        public function PaperVideo(){
        	stage.frameRate = 60;   	
            sceneWidth = stage.stageWidth
            sceneHeight = stage.stageHeight;
            init(sceneWidth,sceneHeight); // Calls init() function found in PaperBase class
        override protected function init3d(): void {
        	videoMaterial();  // Create video Material texture
        	/* public function Plane( 	material:MaterialObject3D=null, 
        								segmentsH:Number=0 ) */
        	//	NOTE:The width and height parameters should match your video footage otherwise the video will be warped.
        	videoPlane =  new Plane( videoStreamMaterial, 480, 360, 10 , 10 );
	   		videoPlane.scale =  2;
        public function videoMaterial() : void {
			var customClient:Object = new Object();
			/* MetaDataHandler is a function that catches the metaData 
			if you don't have this flash will throw an error */
			customClient.onMetaData = metaDataHandler; 
			/*  When you use the NetConnection class, consider the following security model:
				Loading and playing an audio or video file is not allowed if the calling 
				file is in a network sandbox and the file to be loaded is local.
				By default, loading and playing an audio or video file is not allowed 
				if the calling file is local and tries to load and play a remote file. 
				A user must grant explicit permission to allow this. */ 
			netConnection = new NetConnection();
			/* The NetStream class opens a one-way streaming connection between a Flash Player */
			netStream = new NetStream(netConnection);
			netStream.client = customClient; "assets/video.f4v" );
			/* By defulat videos are set width:320, height:240 - make sure you set the video 
			to match the exsact pixel size of your video fottage otherwise the videos resiltions will get warped	*/ 
			video = new Video(480,360);  // In this example the video footage is 480w, 360h
			video.smoothing = true;  	 // Makes video look a better especially if video is scaled - 														
			/* public function VideoStreamMaterial ( 	video:Video, 
														stream:NetStream , 
														precise:Boolean = false, 
														transparent:Boolean = false )  */
			videoStreamMaterial = new VideoStreamMaterial(video, netStream, true, false);
			videoStreamMaterial.doubleSided = true;		// Set texture viewable from both sides		
        private function metaDataHandler(infoObject:Object):void {
        override protected function processFrame(): void {
            videoPlane.rotationY += .5;      

Befor you can test localy you will need to change your Adobe Flash Player Security Settings. Otherwise your local video files will not play and give you an error. The two ways around this problem are upload you files to a webserver and test them from the internet or simple go to adobes website and edit your personal flash security settings.


of course you are. why? Well it is a volation of the Adobe Flash Player Security Settings.

SecurityError: Error #2148:
SWF file file:///C|PaperVideo.swf cannot access local resource assets/video.f4v.
Only local-with-filesystem and trusted local SWF files may access local resources.
at PaperVideo/videoMaterial()
at PaperVideo/init3d()
at PaperBase/init()
at PaperVideo()

HOW to edit your Adobe Flash Player Security Settings

1.You must have an internet connection. Heaven forbid you are testing you flash vidoe app in the middle of a dessert with no internet connect. Becuase your out of luck you can only edit the security settings from online.

2. GO to this web page - this is also the same place you would go to allow flash to have acessse to your webcam.

3. You should be on the Global Security Setting tab. If not click on the tab you page should look like this.

4. Add a new Trusted location. This tells your flash player that it is ok to asscess stremming ressocreus like the netStream class we use in this video example.

5. You can add a particale file, but its easyier to just add the folder where all you flash project are held.
6. Once you have added the trusted location your file willl no longer give you an error and you can test video applications localy.