Putting Video on a CS4 (Flash 10) Primitive

March 10, 2009


Get ready to eliminate 1000’s of lines of Papervision3D code. That’s right! By using CS4 you no longer need the Movie Material class, the DisplayObject3D class, the Video Stream Material class, and a plethora of Triangle/UV parsing and math classes. It’s just amazing…in CS4 it’s so simple!

Video on a CS4 Primitive

Video on a CS4 Primitive





Note: This discussion uses the code and results of two previous posts:

Adding Video to a Papervision3D Curved Plane

CS4 Super Primitive using Matrix3D

Placing video on the CS4 Super Prim developed in Chapter 3 of the book is very easy and only requires four steps.

  • Step 1: Import the net and media classes in to the Super Prim Class (see the post on CS4 Super Primitive using Matrix3D – this is your starter code)
  • Step 2: Declare the video, net Connection, and net Stream variables.

//net stream assets
private var myConnection : NetConnection;
private var myStream : NetStream;
private var myVideo : Video;

  • Step 3: Incorporate the loadMyVideo() method discussed in the previous post on Adding Video to a Papervision3D Curved Plane
  • Step 4: Create a bitmapData object and in the animation loop draw your video to that bitmapData object and attach the net stream to your video, as shown below:

//Draw Video into Bitmap
bitmapData.draw( this.myVideo);
this.myVideo.attachNetStream ( this.myStream );

The results yield a video being played among the various prims contained in the super prim. At this point you change the video by changing the file name inside your net Stream method (myStream.play(“assets/eternity.flv”)), but the constructor function could be easily changed to receive a video string locater.

A Little Extra

Also in Chapter 4 of the book, we show you how to put your webcam video on a prim. Below is a shot of my Guinea Pig Don Pedro who jumped into the screen to get his web cam video on a sphere.

Pig on a WebCam

Pig on a Web Cam

The code for this is included in the download above. But the explanation is in the book. To see the entire code download the source from the link above, or click the more button below:

Read the rest of this entry »


Adding Video to a Papervision3D Curved Plane

March 9, 2009


Note: This post lays the foundation for my next post which shows how to put video on a CS4 Primitive at

Putting Video on a CS4 Primitive

(here we do it for Papervision3D).

The real power of Papervision3D is its strong OOP (object oriented) structure. It lets you to do some very robust things, such as put video on any primitive. And in this post, you place a simple video on a curved Plane (developed in Chapter 3 of the book).

Video on a Curved Primitive

Video on a Curved Primitive




Here the basics on how it’s created.

At the heart of the program is the NetStream class that allows you to bring a video into Flash. This class will be discussed in greater detail in Chapter 11, which is on the Flash Media Server. The two important import classes are media and net classes, which contain Sound, Video, and net Connection methods. Armed with these you can instantiate your video net Connection and net Stream.

//net stream assets
private var myConnection : NetConnection;
private var myStream : NetStream;
private var myVideo : Video;

In addition to setting up Papervision3D and bringing in your curved video prim (which was covered in Chapter 3), you must load your video into your net Stream and then attach that net Stream to your instantiated video (myVideo) so you can play it on your curved prim.

private function loadMyVideo():void
//Set up Net Connection
myConnection = new NetConnection();
//Not on the media server
myStream = new NetStream(myConnection);
//Set buffer time
myStream.bufferTime = 2;
//Set up My Stream for client
myStream.client = new Object();
//Instantiate the video
myVideo = new Video(320, 240);
//Attach to local client side video

One of the important tricks, shown in the code above, it to set your net Connection “connect” to null.


This lets you stream from a local server (as opposed to a Flash Media Server). And as usual you run into the Flash security sandbox issue for streams coming from a server without a cross-domain policy. If you’ve been developing in Flash for a while you are familiar with this issue. And later in the book, you’ll learn how to use a little PHP to get around such problems.

After attaching your net Stream to your instantiated video object you can now place it on your curved prim.

videoMaterial = new VideoStreamMaterial(myVideo, myStream);
//videoMaterial.interactive = true;
videoMaterial.doubleSided = true;

//plane = new Plane(material applied to object, width, height, wSegments, hSegments);
planeCurve = new CurvedPlane(videoMaterial,32,24,8,8,10);

You’ll finally ready to use your Video Stream Material.

Place your video and stream in the Video Stream Material. Declare it double sided so when you spin your curved plane you see the video on the other side. Place that videoMaterial on your curved plane. And add that plane to your scene. Ta-da, video on a prim!