package { import away3d.containers.View3D; import away3d.core.math.Number3D; import away3d.core.render.Renderer; import away3d.primitives.RegularPolygon; import away3d.test.Button; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; [SWF(width="500", height="200", frameRate="60", backgroundColor="#FFFFFF")] public class Basic08_regular_polygon extends Sprite { private var view:View3D; private var polygon:RegularPolygon; private var cover:Cover; public function Basic08_regular_polygon() { // add a button to re-set the rotation (rotate mesh, but not object valuse) var bt1:Button = new Button("Increase complexity",160,20); bt1.x = 10; bt1.y = 10; bt1.addEventListener(MouseEvent.CLICK,increaseDensity); this.addChild(bt1); // add a button to toggle between the two ways of moving var bt2:Button = new Button("Decrease complexity",160,20); bt2.x = 10; bt2.y = 40; bt2.addEventListener(MouseEvent.CLICK,decreaseDensity); this.addChild(bt2); // create a viewport view = new View3D({x:250,y:110, renderer:Renderer.CORRECT_Z_ORDER}); addChild(view); view.camera.y = 300; // Move camera up view.camera.lookAt( new Number3D(0,0,0)); // Point it toward scene center again, so the target is right (setting y does not change where the camera is pointing) // create a cube and put it on stage polygon = new RegularPolygon({radius:200,sides:3}); view.scene.addChild(polygon); // add the cover that prevents the problem with too many SWF files running at once view.render(); cover = new Cover(this,500,400); addChild(cover); // render on enterframe this.addEventListener(Event.ENTER_FRAME,render); } private function decreaseDensity(e:MouseEvent):void { if(polygon.sides > 2){ polygon.sides -= 1; } } private function increaseDensity(e:MouseEvent):void { polygon.sides += 1; } private function render(e:Event):void { if(!cover.visible) { // Rotate the cube polygon.rotationY += 1; // Render the view view.render(); } } } }