flash_lines_003
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
function circle():void{
graphics.clear();
for(var h:int=0;h<100;h++){
i=200+r1*Math.cos(x*Math.PI/180);
j=200+r1*Math.sin(x*Math.PI/180);
k=200+r2*Math.cos(y*Math.PI/180);
l=200+r2*Math.sin(y*Math.PI/180);
graphics.lineStyle(1,Math.random()*0xffffff);
graphics.moveTo(i,j);
x=x+10;
y=y+10;
graphics.lineTo(k,l);
}
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
class Slider extends Sprite {
private var options:Object = {width:400, height:15, minValue:0, maxValue:100, onUpdate:null, onChange:null};
private var sliderHolder:Sprite;
private var track:Sprite;
private var grip:Sprite;
public function Slider(o:Object=null) {
for (var prop:String in o) {
try {
options[prop] = o[prop];
} catch (e:Error) {}
}
sliderHolder = new Sprite(); //holds everything
sliderHolder.name = 'slider';
track = new Sprite(); //slider track
track.graphics.beginFill( 0x000000, 0.3 );
track.graphics.drawRect(0, 10, o.width, o.height/5);
track.graphics.endFill();
track.name = 'track';
grip = new Sprite(); //slider grip
grip.graphics.beginFill( 0xff0000, 1 );
grip.graphics.drawRect(0, 0, o.height/3, o.height);
grip.graphics.endFill();
grip.mouseEnabled = false;
grip.name = 'grip';
sliderHolder.addChild(track);
sliderHolder.addChild(grip);
addChild(sliderHolder);
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
track.addEventListener(MouseEvent.MOUSE_DOWN, sliderClick);
}
private function onRemovedFromStage(e:Event):void {
removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
track.removeEventListener(MouseEvent.MOUSE_DOWN, sliderClick);
track,grip,sliderHolder = null;
}
private function sliderClick(e:MouseEvent):void {
updateGripPos();
track.removeEventListener(MouseEvent.MOUSE_DOWN, sliderClick);
stage.addEventListener(MouseEvent.MOUSE_UP, sliderMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, sliderMouseMove);
}
private function updateGripPos():void {
grip.x = Math.round(track.mouseX-grip.width/2);
if(grip.x < 0) grip.x = 0;
if(grip.x > track.width-grip.width) grip.x = track.width-grip.width;
if(options.onChange != null) options.onChange(rangeValue(grip.x/(track.width-grip.width)*100, options.minValue, options.maxValue));
}
private function sliderMouseUp(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, sliderMouseUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMouseMove);
track.addEventListener(MouseEvent.MOUSE_DOWN, sliderClick);
if(options.onUpdate != null) options.onUpdate(rangeValue(grip.x/(track.width-grip.width)*100, options.minValue, options.maxValue));
}
private function sliderMouseMove(e:MouseEvent):void {
e.updateAfterEvent();
updateGripPos();
}
private function rangeValue( per:Number, min:Number, max:Number ):Number {
return ((( max - min ) / 100 ) * per ) + min;
}
}