A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Rotation Help [AS2]

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    2

    Rotation Help [AS2]

    Hello I'm Kingofnukes and this is my first posts here .

    I have this problem with a menu I'm currently making.

    How it works: The user will press left/right arrow key and the item will move to the next "slot".

    My problem: Currently the menu almost does what it's supposed to. It rotates the first 3 to the next slot, but the four zooms around and never stops. (only on left press).

    Here is my source code and .fla

    code:

    var home:MovieClip = this;
    var Dir:String;
    var Slots:Array = [];
    var characters:Array = [["guy1"], ["guy2"], ["guy3"], ["guy4"]];
    var numOfChars:Number = characters.length;
    var Destination:Number;
    var radiusX:Number = 300;
    var radiusY:Number = 75;
    var centerX:Number = Stage.width/2;
    var centerY:Number = Stage.height/2;
    var perspective:Number = 130;
    var easing:Number = 0.05;
    var menuKeyTimer:Number;
    /////////////////////////////////////////////////////////////////////
    this.onLoad = function() {
    menuKeyTimer = 0;
    Destination = 1;
    numOfChars = characters.length;
    for (var i = 0; i<numOfChars+1; i++) {
    var t = home.attachMovie(characters[i], characters[i], i+1);
    Slots.push(i*((Math.PI*2)/numOfChars));
    t.angle = i*((Math.PI*2)/numOfChars);
    t.charID = i+1;
    t.onEnterFrame = mover;
    }
    };
    /////////////////////////////////////////////////////////////////////
    myListener = new Object();
    myListener.onKeyUp = function() {
    menuKeyTimer = 0;
    };
    Key.addListener(myListener);
    ////////////////////////////////////////////////////////////////////
    function mover() {
    this._x = Math.cos(this.angle)*radiusX+centerX;
    this._y = Math.sin(this.angle)*radiusY+centerY;
    var s = (this._y-perspective)/(centerY+radiusY-perspective);
    this._xscale = this._yscale=s*100;
    this.swapDepths(Math.round(this._xscale)+100);
    this._alpha = (Math.round(this._xscale)-45);
    if (Key.isDown(Key.LEFT)) {
    menuKeyTimer++;
    if (menuKeyTimer<2) {
    if (Destination<=numOfChars && Destination>=1) {
    Destination--;
    } else if (Destination<=0) {
    Destination = 4;
    }
    Dir = "Left";
    }
    //trace(Destination);
    }
    if (Key.isDown(Key.RIGHT)) {
    menuKeyTimer++;
    if (menuKeyTimer<2) {
    if (Destination<numOfChars) {
    Destination++;
    } else {
    Destination = 0;
    }
    Dir = "Right";
    }
    //trace(Destination);
    }
    if (this.angle == Slots[Destination+this.charID]) {
    //Stop
    } else {
    if (Dir == "Left") {
    this.angle += Slots[Math.abs(Destination+this.charID)]*easing;
    if (this.angle>10) {
    this.angle = 0;
    } else if (this.angle<0) {
    this.angle = 10;
    }
    } else if (Dir == "Right") {
    this.angle -= Slots[Math.abs(Destination+this.charID)]*easing;
    if (this.angle>10) {
    this.angle = 0;
    } else if (this.angle<0) {
    this.angle = 10;
    }
    } else {
    Dir = "none";
    }
    }
    }

    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Mar 2007
    Posts
    2
    *bump*

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