18 April 2011

AS3 function to rotate a 2D or 3D MovieClip or Sprite around its center or change to any registration point

OK here we go - I looked everywhere for this one but only found bits of code from various forums and blogs that were part of classes and packages and as such, full of dependent variables. Anyway, after a bit of advice from the very helpful community at StackOverflow and a bit of tinkering, she's up and running!

The function below will rotate a DisplayObject around any point on a 2D or 3D plane. This is particularly useful for rotating around an object's center point so this is the default behaviour. Enjoy!

Please see right hand pane before copying my code >>>

function rotObj(mc, angle, axis="Z", regX='center', regY=0, regZ=0) {
 mc.z=mc.z //workaround for matrix3D bug
 if (axis=="X") {
 } else if (axis=="Y") {
 } else if (axis=="Z") {
 if(regX=='center'){//get center point:
 mc.transform.matrix3D.appendRotation(angle, axis);
rotObj(myMC, 45)  //rotates myMC 45 degrees around its center point
rotObj(myMC, 45, "Y") //rotates myMC 45 degrees on Y axis around its center point
rotObj(myMC, 45, "X", 200, 300) //rotates myMC 45 degrees on X axis around the point 200,300


Anonymous said...

Simply doesn't work

Unknown said...

christian louboutin
oakley sunglasses wholesale
kd 10 elite
ray ban sunglasses outlet
pandora charms
true religion jeans sale
ralph lauren outlet
canada goose jackets
ugg boots on sale
chloe sunglassess

Pradeep Appslure said...

Mobile app development company in mumbai

The India said...

PPC Service in Delhi
PPC Companies in Delhi
SEO Company in Delhi
SEO Company in Delhi NCR
SMO Company in Delhi
SMO Company in India

prashant said...

Nice Post!

Best AC in India
Work from Home Jobs
Places to Visit in mumbai
Places to Visit in Delhi

Tekniko Global said...

Looking for a mobile app development company in Delhi? Given our need for constant global connectivity, creative mobile app developers are frequently sought-after. We researched hundreds of app development companies in Noida.
mobile app development company in delhi

Bindhu Lata said...

Nice post I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this   
Salesforce Training India 

Pradeep Appslure said...

Appslure is a mobile Application Development Company in Gurgaon. Our app developers team are expert in iOS, Android, iPhone
Mobile app development company in gurgaon

Pradeep Appslure said...

mobile app development company in delhi

Tekniko Global said...

Tekniko Global is an app development company in delhi. We have core expert for iOS app & Android application development. We provide Custom App development services at reasonable cost.

Flora said...

Thanks for sharing wonderful information. I loved reading your article.
use of python programming
highest paying skills
scope of hadoop
hadoop scope in future
java interview questions and answers for freshers
selenium interview questions and answers pdf

Pradeep Appslure said...

mobile app development agency

Unknown said...

Great Article Image Processing Projects Deep Learning Projects for Final Year JavaScript Training in Chennai JavaScript Training in Chennai The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai

Post a Comment

Cron Design Studio: Dublin based web design & software development