Permalink
Browse files

modified slider

  • Loading branch information...
1 parent 50caf1f commit 9c90075c41a72dc74f6b4c7f44c8e1c1bc900a80 @jessefreeman jessefreeman committed Jul 11, 2010
@@ -5,5 +5,7 @@ package com.flashartofwar.behaviors
function get value():Number;
function set value(value:Number):void;
+
+ function get ticks():Number;
}
}
@@ -50,8 +50,8 @@ package com.flashartofwar.behaviors
protected var _max:Number = 100;
protected var _min:Number = 0;
protected var _orientation:String;
- protected var _tick:Number = 1;
-
+ //protected var _tick:Number = 1;
+ //protected var _numTics:Number = 48; //total width of images / 480, rounded up.
public function SliderBehavior(target:Sprite)
{
@@ -90,6 +90,14 @@ package com.flashartofwar.behaviors
}
/**
+ * Find position of nearest tick
+ */
+ protected function nearestTick(tl:Number, nt:Number, rp:Number):Number
+ {
+ return (tl/nt)*Math.round(nt*rp/tl);
+ }
+
+ /**
* Adjusts value to be within minimum and maximum.
*/
protected function correctValue():void
@@ -139,6 +147,8 @@ package com.flashartofwar.behaviors
dragger.x = target.mouseX - dragger.width / 2;
dragger.x = Math.max(dragger.x, 0);
dragger.x = Math.min(dragger.x, track.width - dragger.width);
+ //this next line has a hilarious effect.
+ dragger.x = nearestTick(track.width - dragger.width, ticks, dragger.x);
_value = dragger.x / (track.width - dragger.width) * (_max - _min) + _min;
}
else
@@ -178,6 +188,21 @@ package com.flashartofwar.behaviors
{
target.stage.removeEventListener(MouseEvent.MOUSE_UP, onDrop);
target.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onSlide);
+ var oldValue:Number = _value;
+ if (_orientation == HORIZONTAL)
+ {
+ //this next line has a hilarious effect.
+ dragger.x = nearestTick(track.width - dragger.width, ticks, dragger.x);
+ _value = dragger.x / (track.width - dragger.width) * (_max - _min) + _min;
+ }
+ else
+ {
+ // _value = (track.height - dragger.height - dragger.y) / (track.height - dragger.height) * (_max - _min) + _min;
+ }
+ if (_value != oldValue)
+ {
+ dispatchEvent(new Event(Event.CHANGE));
+ }
target.stopDrag();
}
@@ -233,7 +258,7 @@ package com.flashartofwar.behaviors
public function get value():Number
{
- return (_value / _tick) * _tick;
+ return _value;//( / _tick) * _tick;
}
/**
@@ -269,14 +294,19 @@ package com.flashartofwar.behaviors
/**
* Gets / sets the tick value of this slider. This round the value to the nearest multiple of this number.
*/
- public function set tick(t:Number):void
+ /*public function set tick(t:Number):void
{
_tick = t;
}
public function get tick():Number
{
return _tick;
+ }*/
+
+ public function get ticks():Number
+ {
+ return ISlider(target).ticks;
}
}
}
@@ -19,11 +19,13 @@ package com.flashartofwar.ui
private var draggerWidth:Number;
private var roundedCorners:Number;
private var maskShape:Sprite;
+ private var _ticks:Number;
- public function Slider(width:Number = 100, height:Number = 10, draggerWidth:Number = 40, roundedCorners:Number = 5)
+ public function Slider(width:Number = 100, height:Number = 10, draggerWidth:Number = 40, roundedCorners:Number = 5, ticks:Number = 0)
{
_width = width;
_height = height;
+ this.ticks = ticks;
this.draggerWidth = draggerWidth;
this.roundedCorners = roundedCorners;
init();
@@ -122,7 +124,15 @@ package com.flashartofwar.ui
return sprite;
}
+ public function get ticks():Number
+ {
+ return _ticks;
+ }
+ public function set ticks(value:Number):void
+ {
+ _ticks = value < 0 ? 0 : value;
+ }
}
}
@@ -19,7 +19,7 @@ public class BitmapScrollerTest extends BitmapScroller
public function BitmapScrollerTest()
{
- var collection:Vector.<BitmapData> = new Vector.<BitmapData>();
+ var collection:Array = [];
for (var i:int; i < 3; i ++)
{

0 comments on commit 9c90075

Please sign in to comment.