I've updated the article on the website with the code... Probably easier..
lol

D







On 2 December 2010 15:13, Darcey Lloyd <[email protected]> wrote:

> Yep... There is very little difference between flex and actionscript
> projects at the end of the day... I just demo using flex as I don't have to
> setup the stage and create sprites for containers. Step by step list below
> and full code without stage setup at bottom.
>
> D
>
>
>
> *Step by step*
> 1. Create new project in flash builder "actionscript", enter name "test"
> and choose specific sdk 3.5, click finish
> 2. Once project is created and listed in left panel, right click it choose
> properties
> 3. Choose "flex compiler" from the popup window, then in right side select
> "use specific version" box enter 10, box 2 enter 1, box 3 enter 0
> 4. Open your actionscript file Test.as
> 5. Copy and paste only the actionscript from my example in below line 10
> 6. Now in the MXML Flex application there were 2 containers created for
> holding the away3d view and 1 for the stats, just make sprites for these..
>
> MXML Was:
>
> <mx:UIComponent id='away3dContainer' visible='true'/>
>       <mx:UIComponent right='130' top='10' id='away3dstatsContainer' 
> visible='true'/>
>
>
> So just create 2 sprites to act as these containers:
>
> Above the line (typical place for variables add) the lines:
>
> private var away3dContainer:Sprite;
> private var away3dstatsContainer:Sprite;
>
> In the constructor add the line
> init();
>
>
> Now you just need to setup these sprites so add 4 lines of code to the top
> of function init()
> away3dContainer = new Sprite();
> this.addChild(away3dContainer);
>  away3dstatsContainer = new Sprite();
> this.addChild(away3dstatsContainer);
>
>
> and your good to go...
>
>
>
>
>
>
> NOTE: When going the pure AS3 route, you should set the stage up with
> stage.align and stage.scale.
>
>
>
>
>
> Full code:
>
> package
> {
> import flash.display.Sprite;
>  import flash.events.Event;
> import flash.events.MouseEvent;
>  public class Test extends Sprite
> {
> private var away3dContainer:Sprite;
>  private var away3dstatsContainer:Sprite;
>   public function Test()
> {
> init();
>  }
>  import away3d.cameras.HoverCamera3D;
>  import away3d.containers.Scene3D;
> import away3d.containers.View3D;
> import away3d.core.base.Vertex;
>  import away3d.core.render.BasicRenderer;
> import away3d.core.utils.Cast;
>  import away3d.debug.AwayStats;
> import away3d.events.MouseEvent3D;
> import away3d.materials.*;
>  import away3d.primitives.*;
>  import com.greensock.TweenLite;
>  import flash.utils.getTimer;
>    //
> ------------------------------------------------------------------------------------------------
> // Embedded asssets
>  //
> ------------------------------------------------------------------------------------------------
>  // Var ini
> private var scene:Scene3D;
> private var camera:HoverCamera3D;
>  private var view:View3D;
> private var renderer:BasicRenderer;
>  private var bMove:Boolean = false;
> private var lastPanAngle:Number;
> private var lastTiltAngle:Number;
>  private var lastMouseX:Number;
> private var lastMouseY:Number;
>  // Working vars
> private var plane:Plane;
> private var matFront:VideoMaterial;
>  private var matFrontURL:String = "assets/vid1.flv";
>  private var matBack:VideoMaterial;
>  private var matBackURL:String = "assets/vid2.flv";
> //
> ------------------------------------------------------------------------------------------------
>    //
> ------------------------------------------------------------------------------------------------
> public function init():void
>  {
> away3dContainer = new Sprite();
> this.addChild(away3dContainer);
>  away3dstatsContainer = new Sprite();
> this.addChild(away3dstatsContainer);
>  // Setup Away3D
> camera = new HoverCamera3D();
>  renderer = new BasicRenderer();
>  scene = new Scene3D();
>  view = new View3D();
> view.scene = scene;
> view.camera = camera;
>  view.renderer = renderer;
> view.x = stage.stageWidth / 2;
> view.y = stage.stageHeight / 2;
>  // Setup away3d stats (appears to slow the cpu)
> var awaystats:AwayStats = new AwayStats(view);
>  away3dstatsContainer.addChild(awaystats);
>  //var tr:Trident = new Trident(500,true);
>  //scene.addChild(tr);
>  // Setup camera
>  camera.minTiltAngle = -10;
> camera.maxTiltAngle = 10;
> camera.panAngle = 180;
>  camera.tiltAngle = 5;
> camera.zoom = 8;
>  // Add Away3D to its container UIComponent
> away3dContainer.addChild(view);
>  // Resize handler
> this.addEventListener(Event.RESIZE,handleBrowserResize);
>  handleBrowserResize();
>  // Enter frame handler (make things move)
>  stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
> stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
>  stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
>  // generate
>  generateScene();
> }
> //
> ------------------------------------------------------------------------------------------------
>      //
> ------------------------------------------------------------------------------------------------
> private function generateScene():void
>  {
> matFront = new VideoMaterial({file:matFrontURL,loop:true});
> matFront.volume = 0;
>  matFront.interactive = false;
> matFront.smooth = true;
>  matBack = new VideoMaterial({file:matBackURL,loop:true});
> matBack.volume = 0;
>  matBack.interactive = false;
> matBack.smooth = true;
>  plane = new Plane({width:480,height:320});
> plane.bothsides = true;
> plane.material = matFront;
>  plane.back = matBack;
> plane.rotationX = 90;
> scene.addChild(plane);
>  // Spin things round to let people know the obvious
> TweenLite.to(camera,3,{delay:1.5,panAngle:540});
>  }
> //
> ------------------------------------------------------------------------------------------------
>     //
> ------------------------------------------------------------------------------------------------
>  private function onEnterFrame(event:Event):void
> {
> // Camera movement
>  if (bMove) {
> camera.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle;
>  camera.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle;
> }
>   // Convert pan angle to a range of 0 to 360
>  var pDivs:Number = Math.floor((camera.panAngle/360));
> var nPanAngle:Number = camera.panAngle - (pDivs * 360);
>   // Handle volume for front material
>  var nMat1Volume:Number = 0;
> var nStep:Number = 1/90;
> if (nPanAngle > 90 && nPanAngle < 180)
>  {
> nMat1Volume = nStep * (nPanAngle - 90);
> } else if (nPanAngle >= 180 && nPanAngle < 270)
>  {
> nMat1Volume = 1 -  ((nStep * (nPanAngle - 180)));
> } else {
>  nMat1Volume = 0;
> }
>  matFront.volume = nMat1Volume;
>   // Handle volume for front material
> var nMat2Volume:Number = 0;
>  if (nPanAngle >= 0 && nPanAngle <= 90)
> {
> nMat2Volume = 1 - (nStep * (nPanAngle));
>  } else if (nPanAngle >= 270)
> {
> nMat2Volume = 1 - (nStep * (360-nPanAngle));
>  } else {
> nMat2Volume = 0;
> }
>  matBack.volume = nMat2Volume;
>    // Hover camera
>  camera.hover();
>  // Render
>  view.render();
> }
> //
> ------------------------------------------------------------------------------------------------
>     //
> ------------------------------------------------------------------------------------------------
>  private function mouseDownHandler(event:MouseEvent):void
> {
> lastPanAngle = camera.panAngle;
>  lastTiltAngle = camera.tiltAngle;
> lastMouseX = stage.mouseX;
> lastMouseY = stage.mouseY;
>  bMove = true;
>  stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>  }
> //
> ------------------------------------------------------------------------------------------------
>  //
> ------------------------------------------------------------------------------------------------
> private function mouseUpHandler(event:MouseEvent):void
>  {
> bMove = false;
> stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>  }
> //
> ------------------------------------------------------------------------------------------------
>  //
> ------------------------------------------------------------------------------------------------
> private function onStageMouseLeave(event:Event):void
>  {
> bMove = false;
> stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>  }
> //
> ------------------------------------------------------------------------------------------------
>    //
> ------------------------------------------------------------------------------------------------
>  // Browser resize handler (simply adjust view3d center x:0 y:0 at browser
> 1/2 width and height to keep things in the middle
> private function handleBrowserResize(e:Event=null):void
>  {
> this.view.x = stage.stageWidth/2;
> this.view.y = stage.stageHeight/2;
>  }
> //
> ------------------------------------------------------------------------------------------------
>    //
> ------------------------------------------------------------------------------------------------
> private function play(nMatNo:Number):void
>  {
> switch (nMatNo){
> case 1:
>  matFront.netStream.resume();
> break;
> case 2:
>  matBack.netStream.resume();
> break;
> }
>  }
> //
> ------------------------------------------------------------------------------------------------
>  //
> ------------------------------------------------------------------------------------------------
> private function stop(nMatNo:Number):void
>  {
> switch (nMatNo){
> case 1:
>  matFront.netStream.pause();
> break;
> case 2:
>  matBack.netStream.pause();
> break;
> }
>  }
> //
> ------------------------------------------------------------------------------------------------
>   }
> }
>
>
>
>
>
>
>
>
>
> On 2 December 2010 14:28, Tony Brown <[email protected]> wrote:
>
>> Hi Darcey,
>>
>> Sorry for the stupid question, but I am a total newbie to AS3 and this
>> stuff is way over my level of experience, I just started, and prefer to use
>> Flash Builder instead of flash to code  AS3 projects, is there a way to do
>> this as a acrtionscript project instead of a flex project ?
>> what do I have to do to change it from Flex to Actionscript project ?
>>
>> Thanks a million
>>
>> Tony ~
>>
>>
>> On Thu, Dec 2, 2010 at 7:36 AM, Darcey Lloyd <[email protected]>wrote:
>>
>>> Full source and example included:
>>>
>>> http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=4&aid=250
>>>
>>>
>>>
>>> <http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=4&aid=250>
>>>
>>> On 2 December 2010 11:14, pixelBender67 <[email protected]>wrote:
>>>
>>>> Does anyone know of a tutorial for using VideoMaterial ?
>>>>
>>>> On Nov 22, 9:13 am, savagelook <[email protected]> wrote:
>>>> > VideoMaterial
>>>> >
>>>> > On Nov 20, 9:56 am, Tony Brown <[email protected]> wrote:
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > > Hi I am just starting out with Away and As3 in general , and was
>>>> wondering
>>>> > > how to add a video file to
>>>> > > the faces of a Cube or any other surface that I want to add that
>>>> file to, is
>>>> > > there a movieMaterial ?
>>>> >
>>>> > > Thanks so much, any help is greatly appreciated.
>>>> >
>>>> > > Tony ~
>>>>
>>>
>>>
>>
>

Reply via email to