/ Published in: ActionScript 3
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package com.vamapaull.utils { public class ValueConvertor { public static function convertRange(originalStart:Number, originalEnd:Number, newStart:Number, newEnd:Number, value:Number):Number { var originalRange:Number = originalEnd - originalStart; var newRange:Number = newEnd - newStart; var ratio:Number = newRange / originalRange; var newValue:Number = value * ratio; var finalValue:Number = newValue + newStart; return finalValue; } } }
URL: http://blog.vamapaull.com/convert-values-within-a-range-to-values-within-another-range/