Main.as
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="550",height="400",backgroundColor="0x0")]
public class Main extends Sprite{
private const SIZE:Number = 100;
public function Main(){
var spr:Sprite = new Sprite();
spr.x = stage.stageWidth/2;
spr.y = stage.stageHeight/2;
addChild(spr);
makeCube(spr,0x00FFFF);
spr.addEventListener(Event.ENTER_FRAME,rotate);
}
private function makeCube(s:Sprite,c:uint):void{
var f1:Shape = new Shape();
f1.graphics.lineStyle(2,c);
f1.graphics.drawRect(0,0,SIZE,SIZE);
f1.x = -SIZE/2;
f1.y = -SIZE/2;
f1.z = -SIZE/2;
s.addChild(f1);
var f2:Shape = new Shape();
f2.graphics.lineStyle(2,c);
f2.graphics.drawRect(0,0,SIZE,SIZE);
f2.x = -SIZE/2;
f2.y = -SIZE/2;
f2.z = SIZE/2;
s.addChild(f2);
var f3:Shape = new Shape();
f3.graphics.lineStyle(2,c);
f3.graphics.drawRect(0,0,SIZE,SIZE);
f3.rotationY = 90;
f3.x = -SIZE/2;
f3.y = -SIZE/2;
f3.z = SIZE/2;
s.addChild(f3);
var f4:Shape = new Shape();
f4.graphics.lineStyle(2,c);
f4.graphics.drawRect(0,0,SIZE,SIZE);
f4.rotationY = 90;
f4.x = SIZE/2;
f4.y = -SIZE/2;
f4.z = SIZE/2;
s.addChild(f4);
var f5:Shape = new Shape();
f5.graphics.lineStyle(2,c);
f5.graphics.drawRect(0,0,SIZE,SIZE);
f5.rotationX = 90;
f5.x = -SIZE/2;
f5.y = -SIZE/2;
f5.z = -SIZE/2;
s.addChild(f5);
var f6:Shape = new Shape();
f6.graphics.lineStyle(2,c);
f6.graphics.drawRect(0,0,SIZE,SIZE);
f6.rotationX = 90;
f6.x = -SIZE/2;
f6.y = SIZE/2;
f6.z = -SIZE/2;
s.addChild(f6);
}
private function rotate(e:Event):void{
const DUMP:Number = 0.25;
var dx:Number = (mouseX - stage.stageWidth/2);
var dy:Number = (mouseY - stage.stageHeight/2);
e.target.rotationY = -dx*DUMP;
e.target.rotationX = dy*DUMP;
}
}
}
Powered by blog Boreal Kiss 2008.