Wednesday, 7 December 2011

VideoMaterial on Plane with Away3D

I was looking for examples of how to add a video onto a Plane primitive in Away3D 3.6. I couldn’t find many examples online, so I have posted up a quick example.

 import away3d.containers.View3D;
 import away3d.cameras.Camera3D;
 import away3d.containers.Scene3D;
 import away3d.materials.VideoMaterial;
 import away3d.primitives.Plane;
 import flash.display.*;

 [SWF(backgroundColor="#ffffff", frameRate="60", quality="HIGH", width="800", height="600")]
 public class Main extends Sprite
  private static var VIDEO_URL:String = "vid.flv";
  private var scene:Scene3D;
  private var camera:Camera3D;
  private var view:View3D;

  private var plane:Plane;

  public function Main()

  private function createView():void
   //setup away3D
   scene = new Scene3D();
   camera = new Camera3D();
   camera.z = -1000;
   view = new View3D();
   view.scene = scene; = camera;
   view.x = stage.stageWidth / 2;
      view.y = stage.stageHeight / 2;
   //initialise enter frame listener
   addEventListener(Event.ENTER_FRAME, ef);
  private function createScene() : void 
   //video material
   var vidMat:VideoMaterial = new VideoMaterial();
   vidMat.file = VIDEO_URL;
   vidMat.loop = true;
   vidMat.smooth = true;
   vidMat.interactive = false;
   //add plane
   plane = new Plane();
   plane.material = vidMat;
   plane.width = 640;
   plane.height = 360;
   plane.yUp = false;
   plane.bothsides = true;
  private function ef(event : Event) : void 
   plane.rotationY += 0.5;

I ran into some issues getting the FLV file to play locally. It was the ‘SecurityError: Error #2148’. To get this working in FDT I added following compiler argument: -use-network=false

If you are using the Flash IDE, in the publish settings set the Local playback security: Access local files only

Alternatively, you can upload your files on to a web server and view the files. If you are using a Mac enable personal web sharing and add the files into the web sharing folder.


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP