A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: math for rotated dragging

  1. #1
    Join Date
    Mar 2007

    math for rotated dragging

    Hi all,

    this math isn't working well. I'm using it for a rotated drag and drop (of a tone arm on a vinyl, a kind of abstract turntable simulation). Right now it just moves a bit in the middle of the vinyl (values between
    21 and 36, is this degree or what unit is this?), but it should move between the two edges. The problem is that I don't know enough about trigonometry functions. Therefore I can't optimize the math for envisaged behaviour.
    Does anybody have an idea/tip how I can get a bit more control on the math and its effect? (maybe with more trace functions)

    Thanks in advance.


    code in actionscript document:
    Actionscript Code:
    package mathfiles.com.flashcreations.utils {
        public class MathExtra {

        public static function randomBetween(a:Number, b:Number):Number {
            return (a + Math.floor(Math.random()*(b-a+1)));

        public static function rotation2(dx:Number, dy:Number):Number {
            return Math.atan2(dy, dx) * (45/Math.PI);

    code in frame:
    Actionscript Code:
    import mathfiles.com.flashcreations.utils.MathExtra;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.events.Event;
    import flash.net.URLRequest;

    var trk1:Sound = new Sound();
    var trkChannel1:SoundChannel;
    var req:URLRequest = new URLRequest("Sound/aleatoric inspiration_2.mp3");

    stage.addEventListener(MouseEvent.MOUSE_DOWN, pressHandler);

    function pressHandler(e:Event):void {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
        stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
    function moveHandler(e:Event):void {
        if (mc_area.hitTestPoint(mouseX,mouseY,true)) {
    //  trace(mc_arm.rotation);
    function upHandler(e:Event):void {
        stage.removeEventListener(MouseEvent.MOUSE_UP, upHandler);
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
        var starts:Number=(((mc_arm.rotation-21)/17)*trk1.length);
        trkChannel1 = trk1.play(starts);
    //  trace(starts);

  2. #2
    Join Date
    Aug 2010
    from the looks of it the problem might be - 180/Pi not 45/Pi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center