1

Actionscript 3 draggable objects and kinematics example

Posted January 22nd, 2010 in Uncategorized and tagged , by pixelbyter

I wrote this example a couple of years ago while researching Actionscript 3, inverse kinematics and the mathematic principles behind motion. I’m currently porting it to a CSS3 example.


Get the Flash source files here.

The following Actionscript 3 snippet is the bread and butter of the code that makes the above example possible:

//calculates angle of centre
var dx:Number = mouseX - thisPhoto.x;
var dy:Number = mouseY - thisPhoto.y;
var angle:Number = Math.atan2(dy, dx);

//handles spinning
var newRotation:Number = (angle - thisPhoto.origAngle) * 180 / Math.PI;

//handles dragging
var newX:Number = mouseX - Math.cos(angle) * thisPhoto.distanceToCentre;
var newY:Number = mouseY - Math.sin(angle) * thisPhoto.distanceToCentre;

//sets new positioning
thisPhoto.x = newX;
thisPhoto.y = newY;
thisPhoto.rotation = newRotation;
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • MySpace
  • Reddit
  • StumbleUpon
  • Twitter

One Response so far.

  1. Sharedtut says:

    @pixelbyter – thank you for sharing

    actionscript 3 makes it so easy

Leave a Reply