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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
package
{
import flash.display.Sprite;
import flash.filters.BevelFilter;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class Trackbar extends Sprite
{
private var w:int;
private var h:int;
private var _trackcolor:int;
private var _taille:int;
private var _min:int;
private var _max:int;
private var _position:Number;
private var _orientation:String;
private var _height:Number;
private var _width:Number;
private var bevel:BevelFilter;
private var myfilterArray:Array;
private var cur: Trackcur = new Trackcur();
private var mc:flash.display.MovieClip;
private var rect:Rectangle;
public function Trackbar():void
{
if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_orientation='horizontal';
x=10;
y=10;
w=100;
h = 20;
_height = h;
_width = w;
_taille = 100;
_trackcolor=0xff0000;
mc = new MovieClip();
bevel=new BevelFilter(0.3,45,0xc0c0c0,0.8,0,0.9,5,5,5,3,'inner');
myfilterArray = new Array();
myfilterArray.push(bevel);
with (graphics)
{
beginFill(_trackcolor);
drawRect(0, 0, w, h);
endFill();
}
filters = myfilterArray;
graphics.drawRect(0, 0, w, h);
with (mc)
{
filters = myfilterArray;
graphics.beginFill(0xFFFBF0);
graphics.drawRect(w / 15, h / 4, w - 2 * w / 15, 3);
graphics.endFill();
//graduations extrêmes
graphics.lineStyle(1,0xc0c0c0);
graphics. moveTo(w/15,h/4+5);
graphics.lineTo(w/15,h/4+5.5);
graphics. moveTo(w-w/15,h/4+5);
graphics.lineTo(w - w / 15, h / 4 + 5.5);
}
addChild(mc);
addChild(cur);
cur.y = h / 3.3;
cur.buttonMode = true;
rect= new Rectangle(w / 15, h / 3.3, w - 2*w / 15, 0);
cur.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseup);
addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheel);
}
private function mouseWheel(event:MouseEvent):void
{
var temppos:int;
temppos = _position;
if (event.delta > 0) event.delta = 1; else event.delta = -1;
_position+= event.delta;
if (_position >= _min && _position <= _max) cur.x = w / 15 + (_position - _min) * (w - 2 * w / 15) / (_max - _min); else _position = temppos;
onChange();
}
private function mousedown(e:MouseEvent):void
{
cur.startDrag(false , rect);
}
private function mouseup(e:MouseEvent):void
{
cur.stopDrag();
}
private function mousemove(e:MouseEvent):void
{
_position = Math.round((cur.x - w / 15) * (_max - _min) / (w - 2 * w / 15) + _min);
onChange();
}
public function onChange():void
{
}
//LES GETTERS
public function get Taille():Number
{
return width;
}
public function get Height():Number
{
return _height;
}
public function get TrackColor():int
{
return _trackcolor;
}
public function get min():int
{
return _min;
}
public function get max():int
{
return _max;
}
public function get Orientation():String
{
return _orientation;
}
public function get Position():int
{
return _position;
}
public function get Width():Number
{
return _width;
}
//LES SETTERS
public function set Taille(value:Number):void
{
scaleX = value / w;
scaleY = scaleX;
}
public function set Height(value:Number):void
{
scaleY=value/h;
}
public function set Width(value:Number):void
{
scaleX = value / w;
}
public function set TrackColor(value:int):void
{
with(graphics)
{
clear;
beginFill(value);
drawRect(0, 0, w, h);
endFill();
}
}
public function set Min(value:int):void
{
_min = value;
}
public function set Max(value:int):void
{
_max = value;
}
public function set Position(value:int):void
{
cur.x = w / 15 + Math.abs(value -_min) * (w - 2 * w / 15) / (_max - _min);
_position = value;
}
public function set Orientation(value:String):void
{
if (value=='vertical')
{
rotation = -90;
y = y + w*scaleX;
}
_orientation = value;
}
public function graduation():void
{
var l:Number;
var grad:Number;
var nbgrad:int;
l=13*w/15;
nbgrad=_max-_min;
grad = l / nbgrad;
graphics.lineStyle(1,0xc0c0c0);
for ( var i: int = 1; i < nbgrad; i++ )
{
graphics.moveTo(w/15+grad*i,h/4+5);
graphics.lineTo(w / 15 + grad * i, h / 4 + 5.25);
}
}
}
}
import flash.display.MovieClip;
import flash.geom.Matrix;
class Trackcur extends flash.display.MovieClip
{
public function Trackcur():void
{
var myMatrix:Matrix = new Matrix();
myMatrix.createGradientBox(4, 4, 0, -1, 0);
with (graphics)
{
beginGradientFill('linear', [0xf5f5f5, 0xf0f0f0, 0xa0a0a0], [100, 100, 100], [0, 2, 210], myMatrix);
moveTo(-2,-2);
lineTo(2,-2);
lineTo(2,0);
lineTo(0,4);
lineTo(-2,0);
lineTo(-2,-2);
}
}
} |
Partager