Posted By

vamapaull on 02/23/12


Tagged

number actionscript flash Value utility general 30 stuffactionscript convertor


Versions (?)

Convert values within a range to values within another range


 / Published in: ActionScript 3
 

URL: http://blog.vamapaull.com/convert-values-within-a-range-to-values-within-another-range/

I’m sharing with you a little utility that I find myself using a lot lately. This utility is a value convertor that you can use in those times when you need to make a volume slider or something similar where you’ll need to change a value and a value range.

  1. package com.vamapaull.utils
  2. {
  3. public class ValueConvertor
  4. {
  5. public static function convertRange(originalStart:Number,
  6. originalEnd:Number,
  7. newStart:Number,
  8. newEnd:Number,
  9. value:Number):Number
  10. {
  11. var originalRange:Number = originalEnd - originalStart;
  12. var newRange:Number = newEnd - newStart;
  13. var ratio:Number = newRange / originalRange;
  14. var newValue:Number = value * ratio;
  15. var finalValue:Number = newValue + newStart;
  16. return finalValue;
  17. }
  18. }
  19. }

Report this snippet  

You need to login to post a comment.