A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: myPod "your personal Ipod"

  1. #1
    Member
    Join Date
    Feb 2010
    Posts
    59

    myPod "your personal Ipod"

    var dial=element ("dial2");
    var windowScroller=element ("window

    scroller");

    stage.addEventListener(Event.ENTER_FRAME,rot)


    function rot(evt:Event):void
    {
    var mx=(mouseX-dial.x);
    var my=(mouseY-dial.y);
    dial.rotation= ((Math.atan2(my,mx) *

    180)/pi)+90
    //radians to degrees

    var y0= 5
    var y1= dial.rotation/1.4

    for(var i:Number = 0;i<=130;i++)
    {
    windowScroller.y= y1;
    }
    }
    ----------------------------------------------------------------------
    We have two actors, 'dial' and

    'windowScroller'(these are vector images).

    When the movie starts, the stage is listening

    for when the movie enters a frame. What

    frame? Any frame! When the movie "enters

    frame" the 'rot' function starts. The 'rot'

    function has two additional actors (these

    actors are calculators). 'mx' mx calculates

    the distance between the Mouse's X position

    and the dial's X position and 'my' calculates

    the distance between the mouse's Y positon

    and the dial's Y position.

    The rotation of the dial is calculated by

    taking the Arctangent of my divided by mx

    (this comes from knowing the sine, cosine,

    and tangent of a triangle, and that the

    opposite these are cosecant, secant, and

    cotangent.) I wanted it in degrees so I had

    to do additional math.

    Now, two more actors. These actors are going

    to be used to change the windowScroller's

    position as the dial is rotated. 'y0' is the

    scoller's starting position. 'y1' is the

    scrollers position, based on the rotation of

    the dial. the '1.4' may have to be changed

    according to your liking.

    I made this using simple trigonometry:
    tang=y/x
    In this case y=mouseY and x=mouseX, and the

    arctangent gives the angle when given x and

    y(remember that we used mouseY-dial.yand

    mouseX-dial.x).

    The buttons around the dial and middle button are just buttons that have a sound attatched to them.

    CHECK OUT THE ATTATCHED PHOTO!

    I wrote"roll" so that you can tell where the mouse is rotated to. it rolls around as the mouse rotates around. Also the grey scrollbar moves down and loops its position as you scroll around. I may need to tweak it a bit, but this should get you all started. I LIKE TO KEEP IT SIMPLE.
    Attached Images Attached Images

Tags for this Thread

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