LiTWol @ Oleg Terenchuk

  • Contact
  • About me

User login

What is OpenID?
To prevent automated spam submissions leave this field empty.
  • Log in using OpenID
  • Cancel OpenID login
  • Request new password

litwol's tweets

  • Youth is spent learning to turn our brain on producing results. No one bothers teaching us how to turn it off. Damn you insomnia — 47 weeks 14 hours ago
  •  
  • 1 of 9
  • ››
more
Home

Creating 3d cube movieClip using Sprites and animating rotation through ActionsScript 3.0

Submitted by litwol on Mon, 01/18/2010 - 17:53

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
Tags:
  • ActionScript 3
  • CS4
  • Flash

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

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Recent posts

  • Developing PHP in VIM - VIM IDE for PHP
  • Creating custom fields using Drupal 7 field api
  • Creating 3d cube movieClip using Sprites and animating rotation through ActionsScript 3.0
  • Adding sprite from inside an external class onto stage and animating it using arrow key movement.
  • Playing with flash keyboard click events
  • Script to benchmark API execution time.
  • Very good dvcs guide
  • High throughput web architecture with drupal - *For authenticated users*
  • About me - Oleg Terenchuk
  • Note to self
  • Pre-generating drupal forms
  • Change memcached admin stats page
  • The cult of done

LiTWoL © Oleg Terenchuk - Hosted on Linode.com 360

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.