A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Converting numbers

  1. #1
    Member
    Join Date
    Jun 2002
    Posts
    71

    Converting numbers

    Hey
    I've made a scroller that fits to the inside of a box.
    This means that the distance from the top and bottom of the scrollbar is different whenever you resize the box.

    Lets say at the moment when I scroll the drag bar's y coordinate moves from 12 to 120

    This is fine, but I would like a seperate script that will convert this into out of a hundred. (1-100).

    Any help would be great,
    -rob

  2. #2
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    code:

    function getPos(min:Number, pos:Number, max:Number) {
    var _tracklength:Number = max-min;
    var _trackpos:Number = pos-min;
    return _trackpos/_tracklength;
    }
    function getPCPos(min:Number, pos:Number, max:Number) {
    return Math.round(100*getPos(min, pos, max));
    }
    trace(getPos(12, 56, 120)+" is roughly "+getPCPos(12, 56, 120)+" %");


  3. #3
    Member
    Join Date
    Jun 2002
    Posts
    71
    Thank you AGC

    -rob

    [edit]

    I have edited it to suit my needs and it works perfectly,

    Many thanks!
    Last edited by rob88wells; 02-03-2005 at 02:55 PM.

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