Creating 3d cube movieClip using Sprites and animating rotation through ActionsScript 3.0
The point of this exercise is to learn how to create a 3d object from primitive 2d shapes in Flash ActionScript 3.0.
I added very simple animation effect just to demonstrate that it actually is 3d and rotates.
Note: I left final 6th side out on purpose.
No special instructions to run this code, just drop it into actions editor and preview your movie.
Note that flash has "registration" point. that is the center point of your object when you control it's x and y position on the stage. When creating a complex object such as movieClip that consist of multiple primitive shapes the registration point is always relative to (0,0) coordinate of the container object. if you wish to create different registration point then you must change primitive shapes' coordinate /within/ the container object (ex: sprite1.x = -50, sprite1.y = -50).
import flash.display.*
var mc_mc:MovieClip = new MovieClip();
var sprite1:Sprite = new Sprite();
sprite1.graphics.beginFill(0xFFCC00);
sprite1.graphics.drawRect(0, 0, 100, 100);
sprite1.rotationX = 90;
var sprite2:Sprite = new Sprite();
sprite2.graphics.beginFill(0xCCCCCC);
sprite2.graphics.drawRect(0, 0, 100, 100);
sprite2.x = 100;
sprite2.z = 100;
sprite2.rotationY = 90;
var sprite3:Sprite = new Sprite();
sprite3.graphics.beginFill(0xFF0000);
sprite3.graphics.drawRect(0, 0, 100, 100);
sprite3.z = 100;
var sprite4:Sprite = new Sprite();
sprite4.graphics.beginFill(0x0000FF);
sprite4.graphics.drawRect(0, 0, 100, 100);
sprite4.z = 100;
sprite4.y = 100;
sprite4.rotationX = -90;
var sprite5:Sprite = new Sprite();
sprite5.graphics.beginFill(0x00FF00);
sprite5.graphics.drawRect(0, 0, 100, 100);
sprite5.rotationY = -90;
mc_mc.addChild(sprite1);
mc_mc.addChild(sprite2);
mc_mc.addChild(sprite3);
mc_mc.addChild(sprite4);
mc_mc.addChild(sprite5);
mc_mc.x = 150;
mc_mc.y = 150;
addChild(mc_mc);
setInterval(rotate, 100, mc_mc);
function rotate(mc_mc) {
mc_mc.rotationX += 10;
mc_mc.rotationY += 10;
mc_mc.rotationZ += 10;
}
- 2196 reads

No responses to "Creating 3d cube movieClip using Sprites and animating rotation through ActionsScript 3.0"
Post new comment