Playing around with Flash 10 3d… first attempt
Sunday, August 31st, 2008Here’s my first stab at using the flash 10 player’s 3D capabilities. I wanted to get a sphere rotating around the y-axis, coming towards the viewer, then receding away. The way I did it was I gave the sphere a non-zero z-index, inside a container Sprite, which I then rotated around the y-axis (changing it’s y rotation). Once I saw it I realized I had made a mistake and that this approach wouldn’t work … but it’s a start so here it is anyway.
Note: It uses the Sphere class for the ‘planet’.
If you don’t see a revolving sphere above, then you need to install the flash player 10, which you can get here:
http://labs.adobe.com/downloads/flashplayer10.html
The Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package {
import flash.display.Sprite;
import flash.events.Event;
public class Threed extends Sprite {
private var sphere:Sphere;
private var orbit:Sprite;
public function Threed() {
init();
}
private function init():void {
//create 'planet'
sphere = new Sphere();
//give it a z- value so that rotation on Y axis will cause 'revolution'
sphere.z = 200;
//create orbit to contain planet
orbit = new Sprite();
//position orbit at center of stage
orbit.x = 200;
orbit.y = 200;
//add planet to orbit
orbit.addChild(sphere);
addChild(orbit);
addEventListener(Event.ENTER_FRAME, function(e:Event):void {
//trace("enterframe") ;
orbit.rotationY += 1;
});
}
}
}
// Copyright (c) 2008 David Wilhelm
// MIT license: http://www.opensource.org/licenses/mit-license.php