Archive for February 6th, 2008

06
Feb

Drag in AS3

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

You can place this code in an AS3 document or a custom class, your choice. Thanks to Matt for the snippet Full code after the jump.

AS3 click and drag example
function initDragger(mc:MovieClip):void

{

 mc.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void

 {

 	e.currentTarget.startDrag();

 });

 mc.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void

 {

 	e.currentTarget.stopDrag();

 });}

// Set up drag
initDragger(cir_mc);

Found this useful? How about buying me a coffee - simply click here.

06
Feb

Convert degrees to radians & radians to degrees

These are two useful formulas that you will use more often than not.

degrees to radians

var degrees:Number =  radians * 180 / Math.PI

radians to degrees

var radians:Number = degrees * Math.PI / 180

Found this useful? How about buying me a coffee - simply click here.

06
Feb

Distance Between two Points

This is one of the most useful formulas that I use. This formula measures the distance between any 2 given points…

These points can be coordinates, movie clips, mouse position, ect…

Full code after the jump.

dx = x2 – x1;
dy = y2- y1;
Dist = Math.sqrt(dx*dx + dy*dy)

Found this useful? How about buying me a coffee - simply click here.




Close
E-mail It