In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

電流2本、磁極2個の磁力線

Get Adobe Flash player
by irobutsu 13 Mar 2010
/**
 * Copyright irobutsu ( http://wonderfl.net/user/irobutsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xj00
 */

package{
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Sprite;

    [SWF(width="400", height="400",backgroundColor=0xffffff)]

    public class jiba extends Sprite
    {
	private var V:Vector.<Vector.<int>>;
	private var nowDrag:int = 0 ; 

	private var sbM1:Tsumami , sbM2:Tsumami ; 
	private var sbI1:Tsumami , sbI2:Tsumami ; 

	private var sbE:Tsumami ; 

	private var w:int , h:int ; 

	private var q1:charge,q2:charge,I1:current,I2:current;

	public function jiba():void { 
	    w=400;
	    h=346;

	    sbM1 = new Tsumami(this,-3, -3 , 3 ,0,346,200,"磁荷1=" ,0xff) ;
	    sbM2 = new Tsumami(this, 3, -3 , 3 ,0,364,200,"磁荷2=" ,0xff00ff ) ;
	    sbI1 = new Tsumami(this, 3, -3 , 3 ,200,346,200,"電流1=" ,0xaa00 ) ;
	    sbI2 = new Tsumami(this,-3, -3 , 3 ,200,364,200,"電流2=" ,0xbbbb ) ;
	    sbE = new Tsumami(this,  0,-50,50,0,382,200, "外部磁場上=") ;

	    q1=new charge(this,-3,80,200,0xff);
	    q2=new charge(this,3,120,200,0xff00ff);
	    I1=new current(this,3,300,180,0xaa00);
	    I2=new current(this,-3,300,220,0xbbbb);

	    stage.addEventListener(MouseEvent.MOUSE_DOWN, mPressed);
	    stage.addEventListener(MouseEvent.MOUSE_UP, mReleased);
	    stage.addEventListener(MouseEvent.MOUSE_MOVE, mMove)
	    addEventListener("update",updateEvt);

	    V=new Vector.<Vector.<int>>(w+1);
	    var i:int;
	    for(i=0; i<=w ; i++ ) {
		V[i]=new Vector.<int>(h+1);
	    }
	    update();
	}

	public function mMove(e:MouseEvent ):void { 
	    if( nowDrag !=0 ) {
		update();
	    }
	}

	public function updateEvt(e:Event ):void {
	    q1.setQ(sbM1.value());
	    q2.setQ(sbM2.value());
	    I1.setI(sbI1.value());
	    I2.setI(sbI2.value());

	    q1.update();
	    q2.update();
	    I1.update();
	    I2.update();

	    update();
	}

	public function mPressed( e:MouseEvent ):void { 
	    var mx:int = e.stageX ;
	    var my:int = e.stageY ;

	    if( q1.isNear(mx,my) ) {
		nowDrag = 1 ;
		q1.goDrag();
	    } else if( q2.isNear(mx,my) ) {
		nowDrag = 2 ;
		q2.goDrag();
	    } else if( I1.isNear(mx,my) ) {
		nowDrag = 3 ;
		I1.goDrag();
	    } else if( I2.isNear(mx,my) ) {
		nowDrag = 4 ;
		I2.goDrag();
	    }
	}
	
	public function mReleased( e:MouseEvent ):void { 
	    if( nowDrag ==1 ) {
		q1.endDrag();
	    } else if( nowDrag ==2 ) {
		q2.endDrag();
	    } else if( nowDrag ==3 ) {
		I1.endDrag();
	    } else if( nowDrag ==4 ) {
		I2.endDrag();
	    }
	    nowDrag = 0 ;
	    update();
	}
	
	public function update():void { 
	    var i:int , j:int ;
	    var XX:int, YY:int;

	    var x1:int=q1.X();
	    var x2:int=q2.X();
	    var x3:int=I1.X();
	    var x4:int=I2.X();
	    var y1:int=q1.Y();
	    var y2:int=q2.Y();
	    var y3:int=I1.Y();
	    var y4:int=I2.Y();
	    var Q1:int=q1.Q();
	    var Q2:int=q2.Q();
	    var i1:int=I1.I();
	    var i2:int=I2.I();


	    var R:int;
	    var I:int;

	    var RR:int;
	    var II:int;

	    var DX1:Vector.<int>=new Vector.<int>(w+1);
	    var SQX1:Vector.<int>=new Vector.<int>(w+1);
	    var DX2:Vector.<int>=new Vector.<int>(w+1);
	    var SQX2:Vector.<int>=new Vector.<int>(w+1);
	    var SQX3:Vector.<int>=new Vector.<int>(w+1);
	    var SQX4:Vector.<int>=new Vector.<int>(w+1);

	    var DY1:Vector.<int>=new Vector.<int>(h+1);
	    var SQY1:Vector.<int>=new Vector.<int>(h+1);
	    var DY2:Vector.<int>=new Vector.<int>(h+1);
	    var SQY2:Vector.<int>=new Vector.<int>(h+1);
	    var SQY3:Vector.<int>=new Vector.<int>(h+1);
	    var SQY4:Vector.<int>=new Vector.<int>(h+1);


	    for( XX = 0 ; XX <= w  ; XX++ ) {
		DX1[XX]=XX-x1;
		SQX1[XX]=(XX-x1)*(XX-x1);
		DX2[XX]=XX-x2;
		SQX2[XX]=(XX-x2)*(XX-x2);
		SQX3[XX]=(XX-x3)*(XX-x3);
		SQX4[XX]=(XX-x4)*(XX-x4);
	    }

	    for( YY = 0 ; YY <= h  ; YY++ ) {
		DY1[YY]=YY-y1;
		SQY1[YY]=(YY-y1)*(YY-y1);
		DY2[YY]=YY-y2;
		SQY2[YY]=(YY-y2)*(YY-y2);
		SQY3[YY]=(YY-y3)*(YY-y3);
		SQY4[YY]=(YY-y4)*(YY-y4);
	    }


	    for( XX = 0 ; XX <= w  ; XX++ ) {
		for( YY = 0 ; YY <= h  ; YY++ ) {
		    switch( Q1 ) {
			case 0:
			R=1;
			I=0;
			break;
			case 1:
			R= (DX1[XX]);
			I= (DY1[YY]);
			break;
			case 2:
			R= (SQX1[XX]-SQY1[YY]);
			I= (DX1[XX]*DY1[YY]*2);
			break;
			case 3:
			R= ((DX1[XX])*SQX1[XX]-3*(DX1[XX])*SQY1[YY]);
			I= (3*SQX1[XX]*(DY1[YY])-SQY1[YY]*(DY1[YY]));
			break;
			case -1:
			R= (DX1[XX]);
			I= (y1-YY);
			break;
			case -2:
			R= (SQX1[XX]-SQY1[YY]);
			I= (-2*(DX1[XX])*DY1[YY]);
			break;
			case -3:
			R= ((DX1[XX])*SQX1[XX]-3*(DX1[XX])*SQY1[YY]);
			I= (-3*SQX1[XX]*DY1[YY]+SQY1[YY]*(DY1[YY]));
			break;
		    }

		    switch( Q2 ) {
			case 0:
			RR=1;
			II=0;
			break;
			case 1:
			RR= (DX2[XX]);
			II= (DY2[YY]);
			break;
			case 2:
			RR= (SQX2[XX]-SQY2[YY]);
			II= (DX2[XX]*DY2[YY]*2);
			break;
			case 3:
			RR= (SQX2[XX]*(DX2[XX])-3*(DX2[XX])*SQY2[YY]);
			II= (3*SQX2[XX]*(DY2[YY])-SQY2[YY]*(DY2[YY]));
			break;
			case -1:
			RR= (DX2[XX]);
			II= (-DY2[YY]);
			break;
			case -2:
			RR= (SQX2[XX]-SQY2[YY]);
			II= (-2*DX2[XX]*DY2[YY]);
			break;
			case -3:
			RR= (SQX2[XX]*(DX2[XX])-3*(DX2[XX])*SQY2[YY]);
			II= (-3*SQX2[XX]*DY2[YY]+SQY2[YY]*(DY2[YY]));
			break;
		    }

		    var RRR:Number=R*RR-I*II;
		    var III:Number=R*II+RR*I;

		    var NR:Number;
		    var Acos:Number;
		    var Asin:Number;
		    var A:Number=1.0;
			
		    if( i1 !=0 || i2 != 0 ) {
			var A1:Number=Number(SQX3[XX] + SQY3[YY]);
			var A2:Number=Number(SQX4[XX] + SQY4[YY]);

			if( A1 != 0 ) {
			    switch( i1 ) {
				case 1:
				A=A1;
				break;
				case 2:
				A=A1*A1;
				break;
				case 3:
				A=A1*A1*A1;
				break;
				case -1:
				A=1.0/A1;
				break;
				case -2:
				A=1.0/(A1*A1);
				break;
				case -3:
				A=1.0/(A1*A1*A1);
				break;
			    }
			}
		    
			if( A2 != 0.0 ) {
			    switch( i2 ) {
				case 1:
				A*=A2;
				break;
				case 2:
				A*=A2*A2;
				break;
				case 3:
				A*=A2*A2*A2;
				break;
				case -1:
				A/=A2;
				break;
				case -2:
				A/=(A2*A2);
				break;
				case -3:
				A/=(A2*A2*A2);
				break;
			    }
			}
			A = 0.5*Math.log(A);
			if( sbE.value() != 0 ) {
			    A += sbE.value() * XX / 1000.0 ;
			}
			Acos=Math.cos(A);
			Asin=Math.sin(A);
			
			NR=RRR*Acos-III*Asin;
			III=RRR*Asin+III*Acos;
			RRR=NR;
		    } else {
			if( sbE.value() != 0 ) {
			    var EE:Number = sbE.value() * XX / 1000.0 ;	
			    Acos=Math.cos(EE);
			    Asin=Math.sin(EE);
			    NR=RRR*Acos-III*Asin;
			    III=RRR*Asin+III*Acos;
			    RRR=NR;
			}
		    }

		    var v:Number = Math.atan2(RRR,III);
		    
		    v *= 5.0 ;
		    v /= Math.PI ;
		    V[XX][YY] = int(Math.floor(v)) ;
		}
	    }
	    graphics.clear();
	    graphics.lineStyle(1,0xffffff);
	    graphics.beginFill(0xffffff);
	    graphics.drawRect(0 , 0 , w , h) ;
	    graphics.endFill();

	    var diff:int ;


	    for( XX = 0 ; XX < w ; XX++ ) {
		for( YY = 0 ; YY < h ; YY++ ) {
		    if( !q1.isNear(XX,YY) && !q2.isNear(XX,YY) && !I1.isNear(XX,YY) && !I2.isNear(XX,YY) ) {
			if( V[XX ][YY] != V[XX][YY + 1] ) {
			    graphics.lineStyle(1,0xff0000);
			    graphics.beginFill(0xff0000);
			    graphics.drawRect(XX , YY , 1 , 1) ;
			    graphics.endFill();
			} else if( V[XX][YY] != V[XX + 1][YY] ) {
			    graphics.lineStyle(1,0xff0000);
			    graphics.beginFill(0xff0000);
			    graphics.drawRect(XX , YY , 1 , 1) ;
			    graphics.endFill();
			}
		    }
		}
	    }
	}
    }
}

import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.*;
import flash.system.*;
import flash.geom.*;
import flash.text.*

class Clickable extends Sprite {
    public function Clickable(pp:Sprite):void {
	buttonMode=true;
	pp.addChild(this);
    }

}

class current extends Clickable {
    private var i:int;
    private var hankei:int;
    private var color:int;
    private var nowDrag:Boolean;

    public function I():int { return i;}
    public function X():int {return x;}
    public function Y():int {return y;}

    public function current(pp:Sprite, qq:int,XX:int, YY:int, c:int):void {
	super(pp);
	x=XX;
	y=YY;
	i=qq;
	hankei=10;
	color=c;
	nowDrag=false;
	write();
    }
    public function setI(qq:int):void { i=qq; }

    public function goDrag():void {
	nowDrag=true;
	startDrag(false,new Rectangle(hankei,hankei,400-hankei*2,346-hankei*2));
    }

    public function isNear(xx:int, yy:int):Boolean {
	return (xx-x)*(xx-x)+(yy-y)*(yy-y) < hankei*hankei;
    }

    public function endDrag():void {
	nowDrag=false;
	stopDrag();
	update();
    }

    public function update():void {
	write();
    }

    public function write():void {
	graphics.clear();
	graphics.lineStyle(1,color);
	graphics.beginFill(color);
	graphics.drawCircle(0,0,hankei);
	graphics.endFill();
	if( i > 0 ) {
	    graphics.lineStyle(1,0);
	    graphics.beginFill(0);
	    graphics.drawCircle(0,0,hankei/2);
	    graphics.endFill();
	} else if( i< 0 ) {
	    graphics.lineStyle(1,0);
	    graphics.moveTo(-7*hankei/10,-7*hankei/10);
	    graphics.lineTo(7*hankei/10,7*hankei/10);
	    graphics.moveTo(-7*hankei/10,7*hankei/10);
	    graphics.lineTo(7*hankei/10,-7*hankei/10);
	}
    }
}

class charge extends Clickable {
    private var q:int;
    private var hankei:int;
    private var color:int;
    private var nowDrag:Boolean;

    public function Q():int { return q;}
    public function X():int {return x;}
    public function Y():int {return y;}


    public function charge(pp:Sprite,qq:int,XX:int, YY:int,c:int):void {
	super(pp);
	x=XX;
	y=YY;
	q=qq;
	hankei=10;
	color=c;
	nowDrag=false;
	write();
    }
    public function setQ(qq:int):void { q=qq; }

    public function goDrag():void {
	nowDrag=true;
	startDrag(false,new Rectangle(hankei,hankei,400-2*hankei,346-2*hankei));
    }

    public function isNear(xx:int, yy:int):Boolean {
	return (xx-x)*(xx-x)+(yy-y)*(yy-y) < hankei*hankei;
    }

    public function endDrag():void {
	nowDrag=false;
	stopDrag();
	update();
    }
    public function update():void {
	write();
    }
    public function write():void {
	graphics.lineStyle(1,color);
	graphics.beginFill(color);
	graphics.drawCircle(0,0,hankei);
	graphics.endFill();
	if( q != 0 ) {
	    graphics.lineStyle(1,0xffffff);
	    graphics.moveTo(3-hankei,0);
	    graphics.lineTo(hankei-2 ,0);
	    // ↑マイナス符号
	    if( q> 0 ) {
		graphics.moveTo(0,2-hankei);
		graphics.lineTo(0,hankei-2);
		// ↑プラス符号に
	    }
	}
    }
}




class Plate extends Sprite {
    protected var txt:TextField;
    protected var Width:int;
    public function Plate(pp:Sprite,X:int,Y:int,W:int,s:String):void {
	x=X;
	y=Y;
	txt=new TextField();
	txt.text=s;
	txt.height=18;
	txt.width=W-20;
	txt.y=0;
	addChild(txt);

	Width=W;
	buttonMode=true;
	writeNormal();
	pp.addChild(this);
    }

    protected function writeNormal():void { 
	graphics.clear();
	graphics.lineStyle(1,0xaaaaaa);
	graphics.beginFill(0xdddddd);
	graphics.drawRect(0,0,Width-1,17);
	graphics.endFill();
	graphics.lineStyle(1,0x666666);
	graphics.moveTo(1,17);
	graphics.lineTo(Width-1,17);
	graphics.lineTo(Width-1,1);
    }
}

class MessagePlate extends Plate {
    private var normalTxt:String;
    private var messageTxt:String;
    private var normalColor:int;
    private var messageColor:int;

    public function MessagePlate(pp:Sprite,X:int,Y:int,W:int,s1:String,s2:String,c1:int=0,c2:int=0xff0000):void {
	super(pp,X,Y,W,s1);
	normalTxt=s1;
	messageTxt=s2;
	normalColor=c1;
	messageColor=c2;
	Off();
    }
    public function On():void {
	txt.text=messageTxt;
	txt.textColor=messageColor;
    }
    public function Off():void {
	txt.text=normalTxt;
	txt.textColor=normalColor;
    }
}

class ClickablePlate extends Plate {
    public function ClickablePlate(pp:Sprite,X:int,Y:int,W:int,s:String):void {
	super(pp,X,Y,W,s);

	buttonMode=true;
	addEventListener(MouseEvent.MOUSE_UP,MUp);
	addEventListener(MouseEvent.MOUSE_OVER,MOver);
	addEventListener(MouseEvent.MOUSE_OUT,MOut);
    }

    public function MUp(e:Event):void {
	;
    }

    public function MOut(e:Event):void {
	writeNormal();
    }

    public function MOver(e:Event):void {
	writeHilight();
    }
    protected function writeHilight():void {
	graphics.clear();
	graphics.lineStyle(1,0xffffff);
	graphics.beginFill(0xdddddd);
	graphics.drawRect(0,0,Width-1,17);
	graphics.endFill();
	graphics.lineStyle(1,0xaaaaaa);
	graphics.moveTo(1,17);
	graphics.lineTo(Width-1,17);
	graphics.lineTo(Width-1,1);
    }
}

class Charge extends Sprite {
    private var q:int;
    private var hankei:int;
    private var color:int;
    private var nowDrag:Boolean;

    public function Q():int { return q;}
    public function X():int {return x+hankei;}
    // 中心のx座標を返す。xは左隅なので、半径分足す。
    public function Y():int {return y+hankei;}
    // 中心のy座標を返す。yは上隅なので、半径分足す。

    public function Charge(qq:int,XX:int, YY:int,pp:Sprite):void {
	buttonMode=true;
	pp.addChild(this);
	x=XX;
	y=YY;
	q=qq;
	hankei=10;
	if( qq>0 ) {
	    color=0xbb0000;
	} else {
	    color=0xbb;
	}
	nowDrag=false;
	write();
    }

    public function goDrag():void {
	nowDrag=true;
	startDrag(false,new Rectangle(0,0,400-hankei*2,346-hankei*2));
    }

    public function endDrag():void {
	nowDrag=false;
	stopDrag();
	dispatchEvent(new Event("update"));
    }

    public function update():void {
	write();
    }
    public function write():void {
	graphics.clear();
	graphics.lineStyle(1,color);
	graphics.beginFill(color);
	graphics.drawCircle(hankei,hankei,hankei);
	graphics.endFill();
	if( q != 0 ) {
	    graphics.lineStyle(1,0xffffff);
	    graphics.moveTo(3,hankei);
	    graphics.lineTo(2*hankei-2 ,hankei);
	    // ↑マイナス符号
	    if( q> 0 ) {
		graphics.moveTo(hankei,2);
		graphics.lineTo(hankei,2*hankei-2);
		// ↑プラス符号に
	    }
	}
    }
}



class PushButton extends ClickablePlate{
    public function PushButton(pp:Sprite,L:int,Y:int,WW:int,l:String,c:int=0):void {
	super(pp,L,Y,WW,l);
	txt.x=2;
	txt.textColor=c;
    }
    public override function MUp(e:Event):void {
	dispatchEvent(new Event("allerase",true));
    }
}



class Check extends ClickablePlate {
    private var val:Boolean;
    private var box:Sprite;

    public function Check(pp:Sprite,now:Boolean,X:int,Y:int,W:int,l:String,c:int=0):void {
	super(pp,X,Y,W,l);
	val=now;
	txt.x=16;
	txt.textColor=c;
	box=new Sprite();
	box.buttonMode=true;
	addChild(box);
	write();
    }

    public override function MUp(e:Event):void {
	toggle();
	dispatchEvent(new Event("update",true));
    }

    public function setValue(a:Boolean):void {
	val=a;
	write();
    }


    public function isChecked():Boolean {
	return val;
    }

    public function toggle():void {
	setValue(!val);
    }

    public function update():void {
	write();
    }

    public function write():void {
	box.graphics.clear();
	box.graphics.lineStyle(1,0);
	box.graphics.beginFill(0xffffff);
	box.graphics.drawRect(1,1,14,14);
	box.graphics.endFill();	
	if( val ) {
	    box.graphics.lineStyle(2,0);
	    box.graphics.moveTo(2,11);
	    box.graphics.lineTo(4,11);
	    box.graphics.lineTo(6,13);
	    box.graphics.lineTo(14,3);
	}
    }
}



class Tsumami extends Plate {
    private var val:int;
    private var min:int;
    private var max:int;
    private var label:String;
    private var nowDrag:Boolean;
    private var lever:Sprite;
    private var mizo:Sprite;
    public function Tsumami(pp:Sprite,now:int,minimum:int,maximum:int,X:int,Y:int,WW:int,l:String,c:int=0):void {
	super(pp,X,Y,WW,l);
	txt.textColor=c;
	buttonMode=false;
	nowDrag=false;
	min=minimum;
	max=maximum;
	val=now;
	label=l;
	lever=new Sprite();
	mizo=new Sprite();
	addChild(mizo);
	addChild(lever);
	mizo.x=Width/2;
	mizo.y=6;
	mizo.buttonMode=true;
	lever.buttonMode=true;
	mizo.addEventListener(MouseEvent.MOUSE_UP,mizoMUp);
	mizo.addEventListener(MouseEvent.MOUSE_OVER,mizoMOver);
	mizo.addEventListener(MouseEvent.MOUSE_OUT,mizoMOut);
	stage.addEventListener(MouseEvent.MOUSE_UP,leverMUp);
	lever.addEventListener(MouseEvent.MOUSE_DOWN,leverMDown);
	lever.addEventListener(MouseEvent.MOUSE_OVER,leverMOver);
	lever.addEventListener(MouseEvent.MOUSE_OUT,leverMOut);
	leverNormal();
	mizoNormal();
	update();
    }

    public function leverMUp(e:MouseEvent):void {
    	if(nowDrag ) {
	    endDrag();
    	}
    }
    public function leverMOver(e:MouseEvent):void {
	leverHighlight();
    }
    public function leverMDown(e:MouseEvent):void {
	goDrag();
    }


    public function mizoMUp(e:MouseEvent):void {
	var p:Point=localToGlobal(new Point(lever.x,lever.y) );
	if( e.stageX < p.x+6 ) {
	    oneDown();
	} else {
	    oneUp();
	}
	mizoHighlight(e);
    }
    public function mizoMOver(e:MouseEvent):void {
	mizoHighlight(e);
    }
    public function mizoMOut(e:MouseEvent):void {
	mizoNormal();
    }

    public function mizoNormal():void {
	mizo.graphics.clear();
	mizo.graphics.lineStyle(1,0x555555);
	mizo.graphics.beginFill(0x555555);
	mizo.graphics.drawRect(0,0,Width/2-4,5);
	mizo.graphics.endFill();
	mizo.graphics.lineStyle(1,0);
	mizo.graphics.moveTo(0,5);
	mizo.graphics.lineTo(0,0);
	mizo.graphics.lineTo(Width/2-4,0);
    }

    public function mizoHighlight(e:MouseEvent):void {
	if( nowDrag ) {
	    return;
	}
	var p:Point=localToGlobal(new Point(lever.x,lever.y) );
	mizo.graphics.clear();
	mizo.graphics.lineStyle(1,0x555555);
	mizo.graphics.beginFill(0x555555);
	mizo.graphics.drawRect(0,0,Width/2-4,5);
	mizo.graphics.endFill();
	mizo.graphics.lineStyle(1,0xffffff);
	if( e.stageX > p.x+6 ) {
	    mizo.graphics.moveTo(lever.x-mizo.x,0);
	    mizo.graphics.lineTo(Width/2-4,0);
	    mizo.graphics.beginFill(0xaaaa);
	    mizo.graphics.moveTo(lever.x-mizo.x+8,0);
	    mizo.graphics.lineTo(lever.x-mizo.x+18,3);
	    mizo.graphics.lineTo(lever.x-mizo.x+8,6);
	    mizo.graphics.endFill();
	} else {
	    mizo.graphics.moveTo(lever.x-mizo.x,0);
	    mizo.graphics.lineTo(0,0);
	    mizo.graphics.lineTo(0,6);
	    mizo.graphics.beginFill(0xaaaa);
	    mizo.graphics.moveTo(lever.x-mizo.x-2,0);
	    mizo.graphics.lineTo(lever.x-mizo.x-12,3);
	    mizo.graphics.lineTo(lever.x-mizo.x-2,6);
	    mizo.graphics.endFill();
	}
    }

    public function leverMOut(e:MouseEvent):void {
	if( !nowDrag ) {
	    leverNormal();
	}
    }

    public function oneUp():void {
	setValue(val+1);
    }

    public function oneDown():void {
	setValue(val-1);
    }

    private function XIchi():int{
	return int(Number((Width/2-6)*(val-min))/Number(max-min))+Width/2;
    }


    public function goDrag():void {
	nowDrag=true;
	leverInDrag();
	lever.startDrag(false,new Rectangle(Width/2,0,Width/2-6,0));
    }

    public function endDrag():void {
	nowDrag=false;
	leverNormal();
	lever.stopDrag();
	val=min + int(Number((lever.x-Width/2)*(max-min))/Number(Width/2-6)+0.5);
	update();
    }

    public function setValue(a:int):void { 
	if( a>max ) {
	    a=max;
	}
	if( a<min ) {
	    a=min;
	}
	val=a; 
	update();
    }

    public function value():int {
	return val;
    }

    public function update():void {
	lever.x=XIchi();
	txt.text=label+String(val);
	dispatchEvent(new Event("update",true));
    }

    public function leverNormal():void {
	lever.graphics.clear();
	lever.graphics.lineStyle(1,0x333300);
	lever.graphics.beginFill(0xaa0000);
	lever.graphics.drawRect(0,0,6,18);
	lever.graphics.endFill();	
    }

    public function leverHighlight():void {
	lever.graphics.clear();
	lever.graphics.lineStyle(1,0xaaaa33);
	lever.graphics.beginFill(0xaa0000);
	lever.graphics.drawRect(0,0,6,18);
	lever.graphics.endFill();	
    }

    public function leverInDrag():void {
	lever.graphics.clear();
	lever.graphics.lineStyle(1,0x888800);
	lever.graphics.beginFill(0xee8888);
	lever.graphics.drawRect(0,0,6,18);
	lever.graphics.endFill();
    }
}