Universe Away3d - Episode 2: In the beginning was .... # 000000

    We will continue the development of Away3d by creating the first project with three-dimensional space and an object inside.

    Open Flex Builder, in which the Away3dFP10 library should already be open, and create a new ActionScript Project away3d_prj01_world. We will configure the project for compilation for the 10th flash player, as described in the previous article (in the next articles I will not return to setting up projects) and uncheck the Generate HTML wraper file (launching in the player is faster than in the browser). Now we’ll add the Away3dFP10 library to the Library path: We’ll tweak the code a bit, add metadata for compiling swf, set the dimensions to 600 by 400, framerate 31, and the background color is black, the main class will now look like this:






    package {
     import flash.display.Sprite;
     [SWF (width = "600", height = "400", frameRate = "31", backgroundColor = "0x000000")]
     public class away3d_prj01_world extends Sprite
     {
      public function away3d_prj01_world ()
      {
      }
     }
    }
    


    After all the preparations, we can finally start, and if everything was correct, see a black window in the opened flash player.
    Improve the situation by adding a sphere. Any construction of a three-dimensional world in Away3d starts with creating a View3D object and adding (addChild) to the Display list - this is essentially the window through which you look into the world you built. Set the view to the middle of the screen. Next, a Scene3D object is created and defined as a property of an object of the View3D class - this is actually the foundation of the three-dimensional world of Away3d. Finally, a Sphere object is created and added (addChild) to the Scene3D class object. Then we command that view visualizes (renders) the world. As a result, we will see the sphere in the middle of the window with a randomly specified color. Final code:


    package {
     import away3d.containers.Scene3D;
     import away3d.containers.View3D;
     import away3d.primitives.Sphere;
     import flash.display.Sprite;
     [SWF (width = "600", height = "400", frameRate = "31", backgroundColor = "0x000000")]
     public class away3d_prj01_world extends Sprite
     {
      private var view: View3D;
      private var sphere: Sphere;
      public function away3d_prj01_world ()
      {
       view = new View3D;
       addChild (view);
       // set view postion
       view.x = 300;
       view.y = 200;
       var scene: Scene3D = new Scene3D;
       view.scene = scene;
       sphere = new Sphere;
       scene.addChild (sphere);
       // lets visualyze
       view.render ();
      }
     }
    }
    

    Working example
    Sources

    Also popular now: