Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

Range.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.senocular.utils {
	
	import flash.geom.Point;
	
	public class Range extends Point {
		
		private var _span:Number = 0;
		
		
		public function get min():Number {
			return x;
		}
		public function set min(n:Number):void {
			x = n;
			updateSpan();
		}
		public function get max():Number {
			return y;
		}
		public function set max(n:Number):void {
			y = n;
			updateSpan();
		}
		
		public function get span():Number {
			return _span;
		}
		
		public function Range(min:Number = 0, max:Number = 1) {
			x = min;
			y = max;
			updateSpan();
		}
		
		public function getRandom():Number {
			return x + Math.floor(Math.random()*(_span + 1));
		}
		
		private function updateSpan():void {
			_span = y - x;
		}
	}
}