I have just spent a couple of hours last night getting to grips with Away3D. I just created a little demo that creates a few spheres and then adds an ENTER_FRAME event listener and responds to mouse movement.
You can download the whole thing here: http://harry-northover-code-store.googlecode.com/files/Away3DBasics.zip
Here is a screene:
And here’s the code:
package {
import away3d.cameras.HoverCamera3D;
import away3d.containers.View3D;
import away3d.primitives.Sphere;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.events.Event;
import caurina.transitions.Tweener;
public class Away3DBasics extends Sprite {
public var stageHeightCenter:uint = stage.stageHeight / 2 - 100;
public var stageWidthCenter:uint = stage.stageWidth / 2 + 100;
public var cam:HoverCamera3D = new HoverCamera3D( { zoom:1, focus:200 } );
public var view:View3D = new View3D( { x:stageWidthCenter, y:stageHeightCenter, camera:cam } );
public function Away3DBasics() {
cam.steps = 16;
// Add the view to the stage.
addChild(view);
// Create 20 spheres.
for (var i:uint = 0; i <= 20; i++)
{
var sphere:Sphere = new Sphere();
sphere.invertFaces();
sphere.x = Math.random() * 1000;
sphere.y = Math.random() * 1000;
sphere.z = Math.random() * 600;
sphere.rotationX = Math.random() * 360;
sphere.rotationY = Math.random() * 360;
view.scene.addChild(sphere);
}
// Add Event listeners.
this.addEventListener(Event.ENTER_FRAME, onRun);
// Render the scene...
cam.hover();
view.render();
}
// This is the code for the ENTER_FRAME event.
private function onRun(evt:Event):void {
cam.rotationX = Math.random() * 360;
cam.rotationY = Math.random() * 360;
cam.rotationZ = Math.random() * 360;
cam.pan(Math.random() * 360);
Tweener.addTween(cam, { zoom: (stage.mouseY / stage.stageHeight) * 4 + 0.5, time:0.1, transition:"easeInOutExpo" } );
cam.hover();
view.render();
}
}
}
There you go! I will be doing a lot more stuff with Away3D so keep an eye out!
Harry.
