複数磁石の磁場・磁位
/**
* Copyright irobutsu ( http://wonderfl.net/user/irobutsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cvWr
*/
package{
import flash.system.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.IDataInput;
import flash.accessibility.Accessibility;
import flash.display.Sprite;
import flash.display.Graphics;
[SWF(width="400", height="400",frameRate = "60", backgroundColor=0xffffff)]
public class ManyMagnet extends Sprite
{
private var Q:Magnets ;
private var nowDragQ:int ;
private var cbE:Check ;
private var cbV:Check ;
private var btC:PushButton ;
private var sbEE:Tsumami;
private var ttM:TwoToggle;
private var w:int , h:int ;
private var chgFlgE:Boolean, chgFlgV:Boolean;
private var XX:int;
public function ManyMagnet():void {
var i:int;
Q= new Magnets;
w=400;
h=364;
A=new Vector.<Vector.<int>>(w+1);
V=new Vector.<Vector.<int>>(w+1);
for( i=0 ; i<= w ;i ++ ) {
A[i]=new Vector.<int>(h+1);
V[i]=new Vector.<int>(h+1);
}
nowDragQ = 0 ;
sbEE = new Tsumami(this,0,-100,100,200,382,200,"外部磁場↑=");
btC = new PushButton(280,364,120,"全磁石消去") ;
addChild(btC);
cbE = new Check(false,0,364,140,"磁力線を描く") ;
addChild(cbE);
cbV = new Check(false,140,364,140, "等磁位線を描く") ;
addChild(cbV);
ttM=new TwoToggle("棒磁石を加える(ドラッグで移動)","磁石を消す(ドラッグ不可)",0,382,200);
addChild(ttM);
addEventListener("change",changeEvt);
addEventListener("update",updateEvt);
addEventListener("allerase",alleraseEvt);
addEventListener(Event.ENTER_FRAME,calcWriteOneLine);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mPressed);
stage.addEventListener(MouseEvent.MOUSE_UP, mReleased);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mMove);
write();
}
public function changeEvt(e:Event):void {
chgFlgV=true;
chgFlgE=true;
XX=0;
}
public function updateEvt(e:Event):void {
write();
}
public function alleraseEvt(e:Event):void {
var i:int;
for( i=0; i < Q.count(); i++ ) {
removeChild(Q.M(i));
}
Q.deleteAll();
chgFlgE=true; chgFlgV=true;
write();
}
public function mPressed( e:MouseEvent ):void {
var mx:int = e.stageX ;
var my:int = e.stageY ;
var i:int ;
if( my >= 364 || mx<0 || mx>=400 ) {
return;
}
if( ttM.value()==1 ) {
for( i = 0 ; i < Q.count() ; i++ ) {
if( Q.hitPoint(mx , my , i) ) {
removeChild(Q.M(i));
Q.del(i) ;
dispatchEvent(new Event("change",true) );
return ;
}
}
return ;
} else {
for( i = 0 ; i < Q.count() ; i++ ) {
if( Q.hitPoint(mx , my , i) ) {
XX=-1;
Q.dragStart(i,0,0,400,364);
nowDragQ = i + 1 ;
return ;
} else if( Q.isNPole(mx , my , i) ) {
XX=-1;
nowDragQ = -i - 1 ;
Q.M(i).TurnOn();
return ;
}
}
Q.addNew(mx , my,this) ;
dispatchEvent(new Event("update",true) );
}
}
public function mReleased( e:MouseEvent ):void {
if( nowDragQ > 0 ) {
Q.dragEnd(nowDragQ-1);
dispatchEvent(new Event("change",true));
} else if( nowDragQ < 0 ) {
Q.M(-nowDragQ-1).TurnOff();
dispatchEvent(new Event("change",true));
}
nowDragQ = 0 ;
}
public function mMove( e:MouseEvent ):void {
if( nowDragQ == 0 ) {
return ;
} else if( nowDragQ < 0 ) {
Q.setAngle(e.stageX , e.stageY , -nowDragQ - 1);
}
}
private function write():void { XX=0; }
private var A:Vector.<Vector.<int>>;
private var V:Vector.<Vector.<int>>;
private var SQX1:Vector.<Vector.<int>>;
private var SQX2:Vector.<Vector.<int>>;
private var SQY1:Vector.<Vector.<int>>;
private var SQY2:Vector.<Vector.<int>>;
private var DX1:Vector.<Vector.<int>>;
private var DY1:Vector.<Vector.<int>>;
private var DX2:Vector.<Vector.<int>>;
private var DY2:Vector.<Vector.<int>>;
public function calcWriteOneLine(e:Event):void {
var YY:int;
var i:int;
var l:int=Q.count();
if( l==0 || XX<0 ) {
return;
}
if( XX== 0 ) {
graphics.clear();
graphics.lineStyle(1,0xffffff) ;
graphics.beginFill(0xffffff) ;
graphics.drawRect(0 , 0 , w , h) ;
graphics.endFill();
SQX1=new Vector.<Vector.<int>>(l)
SQY1=new Vector.<Vector.<int>>(l)
DX1=new Vector.<Vector.<int>>(l)
DY1=new Vector.<Vector.<int>>(l)
SQX2=new Vector.<Vector.<int>>(l)
SQY2=new Vector.<Vector.<int>>(l)
DX2=new Vector.<Vector.<int>>(l)
DY2=new Vector.<Vector.<int>>(l)
for(i=0; i< l ; i++ ) {
DX1[i]=new Vector.<int>(w+1);
DY1[i]=new Vector.<int>(h+1);
SQX1[i]=new Vector.<int>(w+1);
SQY1[i]=new Vector.<int>(h+1);
DX2[i]=new Vector.<int>(w+1);
DY2[i]=new Vector.<int>(h+1);
SQX2[i]=new Vector.<int>(w+1);
SQY2[i]=new Vector.<int>(h+1);
for( YY=0; YY<=h ; YY++) {
DY1[i][YY]=YY-Q.NY(i);
SQY1[i][YY]=DY1[i][YY]*DY1[i][YY];
DY2[i][YY]=YY-Q.SY(i);
SQY2[i][YY]=DY2[i][YY]*DY2[i][YY];
}
}
}
for(i=0; i< l ; i++ ) {
DX1[i][XX]=XX-Q.NX(i);
SQX1[i][XX]=DX1[i][XX]*DX1[i][XX];
DX2[i][XX]=XX-Q.SX(i);
SQX2[i][XX]=DX2[i][XX]*DX2[i][XX];
}
if( cbE.isChecked() ) {
var BunsiReal:Number;
var BunsiIm:Number;
var FiveOverPi:Number=5.0/Math.PI;
var EEX:Number=0.001*sbEE.value()*XX;
for( YY=0; YY <= h; YY++ ) {
BunsiReal=1;
BunsiIm=0;
var NReal:Number;
for( i=0; i<l ; i++ ) {
NReal= DX1[i][XX]*BunsiReal-DY1[i][YY]*BunsiIm;
BunsiIm= DX1[i][XX]*BunsiIm+DY1[i][YY]*BunsiReal;
BunsiReal= DX2[i][XX]*NReal+DY2[i][YY]*BunsiIm;
BunsiIm= DX2[i][XX]*BunsiIm-DY2[i][YY]*NReal;
}
if( EEX != 0.0 ) {
var Mcos:Number=Math.cos(EEX);
var Msin:Number=Math.sin(EEX);
NReal=BunsiReal*Mcos-BunsiIm*Msin;
BunsiIm=Msin*BunsiReal+Mcos*BunsiIm;
BunsiReal=NReal;
}
A[XX][YY]=int(Math.floor(FiveOverPi*Math.atan2(BunsiReal,BunsiIm)));
}
chgFlgE=false;
}
if( cbV.isChecked() ) {
for( YY = 0 ; YY <= h ; YY++ ) {
var EBYY:Number=0.002*sbEE.value()*YY;
if( !Q.NearPole(XX, YY) ) {
var V1:Number = 1.0 ;
var V2:Number = 1.0 ;
for( i = 0 ; i < Q.count() ; i++ ) {
V1 *= SQX1[i][XX]+SQY1[i][YY] ;
V2 *= SQX2[i][XX]+SQY2[i][YY];
}
V[XX][YY] = int(Math.floor(-Math.log(V1/V2)+EBYY)) ;
}
}
chgFlgV=false;
}
if( XX >0 ) {
if( cbE.isChecked() ) {
graphics.lineStyle(0,0xff);
for( YY = 0 ; YY < h ; YY++ ) {
if( !Q.NearPole(XX-1, YY) ) {
if( A[XX-1][YY] != A[XX-1][YY + 1] || A[XX-1][YY] != A[XX][YY]){
graphics.beginFill(0xff);
graphics.drawRect(XX-1 , YY , 1 , 1) ;
graphics.endFill();
}
}
}
}
if( cbV.isChecked() ) {
for( YY = 0 ; YY < h ; YY++ ) {
graphics.lineStyle(0,0xaa00);
if( !Q.NearPole(XX-1, YY) ) {
if( V[XX-1][YY] != V[XX-1][YY+ 1]
|| V[XX-1][YY] != V[XX][YY] ) {
graphics.beginFill(0xaa00);
graphics.drawRect(XX-1,YY,1,1);
graphics.endFill();
}
}
}
}
}
XX++;
if( XX >= w ) {
XX=-1;
}
}
}
}
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.IDataInput;
import flash.accessibility.Accessibility;
import flash.display.Sprite;
import flash.display.*;
import flash.system.*;
import flash.geom.*;
import flash.text.*
class Magnet extends Sprite {
private var cosine:Number ;
private var sine:Number ;
private var hankei:int;
private var R:int;
private var nowTurn:Boolean;
function Magnet(xx:int, yy:int, pp:Sprite ){
pp.addChild(this);
hankei=5;
R=30;
x = xx;
y = yy;
cosine = 1.0;
sine = 0.0;
nowTurn=false;
write();
addEventListener(MouseEvent.MOUSE_OVER,MOver);
addEventListener(MouseEvent.MOUSE_MOVE,MOver);
addEventListener(MouseEvent.MOUSE_OUT,MOut);
}
public function Mark():void {
graphics.lineStyle(1,0x8888);
graphics.beginFill(0xaaaaaa);
graphics.drawRect(-3,-3,6,6);
graphics.endFill();
}
public function TurnMark():void {
graphics.lineStyle(1,0x8888);
graphics.beginFill(0xaaaaaa);
graphics.moveTo(
int( 1.5*hankei * sine + (R-hankei/2) * cosine ),
int( -1.5* hankei * cosine + (R-hankei/2) * sine )) ;
graphics.lineTo(
int( -1.5*hankei * sine + (R-hankei/2) * cosine ),
int( 1.5*hankei * cosine + (R-hankei/2) * sine )) ;
graphics.lineTo(
int( -1.5*hankei * sine + (R-hankei) * cosine ),
int( 1.5*hankei * cosine + (R-hankei) * sine )) ;
graphics.lineTo(
int( -3* hankei * sine + R * cosine ),
int( 3*hankei * cosine + R * sine )) ;
graphics.lineTo(
int( -1.5*hankei * sine + (R+hankei) * cosine ),
int( 1.5*hankei * cosine + (R+hankei) * sine )) ;
graphics.lineTo(
int( -1.5*hankei * sine + (R+hankei/2) * cosine ),
int( 1.5*hankei * cosine + (R+hankei/2) * sine )) ;
graphics.lineTo(
int( 1.5*hankei * sine + (R+hankei/2) * cosine ),
int( -1.5*hankei * cosine + (R+hankei/2) * sine )) ;
graphics.lineTo(
int( 1.5*hankei * sine + (R+hankei) * cosine ),
int( -1.5*hankei * cosine + (R+hankei) * sine )) ;
graphics.lineTo(
int( 3* hankei * sine + R * cosine ),
int( -3*hankei * cosine + R * sine )) ;
graphics.lineTo(
int( 1.5*hankei * sine + (R-hankei) * cosine ),
int( -1.5*hankei * cosine + (R-hankei) * sine )) ;
graphics.lineTo(
int( 1.5*hankei * sine + (R-hankei/2) * cosine ),
int( -1.5*hankei * cosine + (R-hankei/2) * sine )) ;
graphics.endFill();
}
public function TurnOn():void {nowTurn=true; write();}
public function TurnOff():void {nowTurn=false; write();}
public function MOver(e:MouseEvent):void {
if( isNPole(e.stageX,e.stageY) || nowTurn ) {
TurnMark();
} else if( isCenter(e.stageX,e.stageY) ) {
Mark();
} else {
write();
}
}
public function MOut(e:MouseEvent):void {
write();
}
public function write():void {
graphics.clear();
graphics.lineStyle(1,0xff0000);
graphics.beginFill(0xff0000) ;
graphics.moveTo(int( - hankei * sine),int( + hankei * cosine ) );
graphics.lineTo(int( + hankei * sine),int( - hankei * cosine ) );
graphics.lineTo(int( + hankei * sine + ( R + hankei ) * cosine ),
int( - hankei * cosine + ( R + hankei ) * sine )) ;
graphics.lineTo(int( - hankei * sine + ( R + hankei ) * cosine ),
int( + hankei * cosine + ( R + hankei ) * sine )) ;
graphics.endFill();
graphics.lineStyle(1,0);
graphics.beginFill(0) ;
graphics.moveTo(int( - hankei * sine),int( + hankei * cosine ) );
graphics.lineTo(int( + hankei * sine),int( - hankei * cosine ) );
graphics.lineTo(int( + hankei * sine - ( R + hankei ) * cosine ),
int( - hankei * cosine - ( R + hankei ) * sine )) ;
graphics.lineTo(int( - hankei * sine - ( R + hankei ) * cosine ),
int( + hankei * cosine - ( R + hankei ) * sine )) ;
graphics.endFill();
if( nowTurn ) {
TurnMark();
}
}
public function X():int {
return x ;
}
public function Y():int {
return y ;
}
public function cos():Number {
return cosine ;
}
public function sin():Number {
return sine ;
}
public function setX( xx:int ):void {
x = xx ;
}
public function setY( yy:int ):void {
y = yy ;
}
public function setCosineSin( c:Number , s:Number ):void {
cosine = c ;
sine = s ;
}
public function isCenter( x1:int , y1:int ):Boolean {
return ( ( x - x1 ) * ( x - x1 ) + ( y - y1 ) * ( y - y1 ) <= hankei * hankei );
}
public function isNPole( x1:int , y1:int ):Boolean {
var xx:int = NX();
var yy:int = NY();
return ( ( xx - x1 ) * ( xx - x1 ) + ( yy - y1 ) * ( yy - y1 ) <= hankei * hankei );
}
public function isSPole( x1:int , y1:int ):Boolean {
var xx:int = SX() ;
var yy:int = SY() ;
return ( ( xx - x1 ) * ( xx - x1 ) + ( yy - y1 ) * ( yy - y1 ) <= hankei * hankei );
}
public function NX():int {
return int(Math.floor(x + R * cosine)) ;
}
public function NY():int {
return int(Math.floor(y+ R * sine )) ;
}
public function SX():int {
return int(Math.floor(x - R * cosine)) ;
}
public function SY():int {
return int(Math.floor(y- R * sine )) ;
}
public function setAngle(xx:int,yy:int):void {
var YY:Number = Number(( yy - y )) ;
var XX:Number = Number(( xx - x )) ;
var RR:Number = Math.sqrt(XX * XX + YY * YY) ;
cosine=XX / RR;
sine=YY / RR ;
}
public function setPoint(xx:int,yy:int):void {
x=xx;
y =yy;
}
}
class Magnets
{
private var magnetList:Array;
function Magnets():void{
magnetList = new Array() ;
Clear() ;
}
public function dragEnd(i:int):void {
if( magnetList.lenth <= i ) {
return;
}
Magnet(magnetList[i]).stopDrag();
}
public function dragStart(i:int,x1:int,y1:int,w1:int,h1:int):void {
if( magnetList.lenth <= i ) {
return;
}
Magnet(magnetList[i]).startDrag(false,new Rectangle(x1,y1,w1,h1));
}
public function Clear():void {
{
if( magnetList.length > 0 ) {
magnetList.splice(0,magnetList.length) ;
}
}
}
public function addNew( xx:int , yy:int ,pp:Sprite):void {
magnetList.push(new Magnet( xx , yy ,pp)) ;
}
public function count():int {
return magnetList.length;
}
public function X( i:int ):int {
return Magnet(magnetList[i]).X() ;
}
public function Y( i:int ):int {
return Magnet(magnetList[i]).Y() ;
}
public function M( i:int ):Magnet {
return Magnet(magnetList[i]);
}
public function cos( i:int ):Number {
return Magnet(magnetList[i]).cos() ;
}
public function sin( i:int ):Number {
return Magnet(magnetList[i]).sin() ;
}
public function setAngle( xx:int , yy:int , i:int ):void {
if( i >= magnetList.length ) {
return ;
}
Magnet(magnetList[i]).setAngle(xx,yy);
Magnet(magnetList[i]).write();
}
public function setPoint( xx:int , yy:int , i:int ):void {
if( i >= magnetList.length ) {
return ;
}
Magnet(magnetList[i]).setPoint(xx,yy);
}
public function NearPole(x1:int, y1:int):Boolean {
var i:int;
for( i=0 ; i< magnetList.length ; i++ ) {
if( isNPole(x1,y1,i) || isSPole(x1,y1,i) ) {
return true;
}
}
return false;
}
public function isNPole( x1:int , y1:int, i:int ):Boolean {
if( i>= magnetList.length ) {
return false;
}
return Magnet(magnetList[i]).isNPole(x1 , y1);
}
public function isSPole( x1:int , y1:int, i:int ):Boolean {
return Magnet(magnetList[i]).isSPole(x1 , y1);
}
public function hitPoint( x1:int , y1:int, i:int ):Boolean {
if( i>= magnetList.length ) {
return false;
}
return Magnet(magnetList[i]).isCenter(x1,y1);
}
public function isNear( x1:int , y1:int ):Boolean {
var i:int ;
for( i = 0 ; i < magnetList.length ; i++ ) {
if( Magnet(magnetList[i]).isCenter(x1,y1) ){
return true ;
}
}
return false ;
}
public function NX( i:int ):int {
return Magnet(magnetList[i]).NX();
}
public function NY( i:int ):int {
return Magnet(magnetList[i]).NY();
}
public function SX( i:int ):int {
return Magnet(magnetList[i]).SX();
}
public function SY( i:int ):int {
return Magnet(magnetList[i]).SY();
}
public function del( i:int ):void {
magnetList.splice(i,1);
}
public function deleteAll():void {
magnetList.splice(0);
}
}
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 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);
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();
setValue(min + int(Number((lever.x-Width/2)*(max-min))/Number(Width/2-6)+0.5));
}
public function setValue(a:int):void {
if( a>max ) {
a=max;
}
if( a<min ) {
a=min;
}
val=a;
update();
dispatchEvent(new Event("change",true));
dispatchEvent(new Event("update",true));
}
public function value():int {
return val;
}
public function update():void {
lever.x=XIchi();
txt.text=label+String(val);
}
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();
}
}
class Clickable extends Sprite {
protected var Width:int;
public function Clickable(X:int,Y:int,W:int):void {
x=X;
y=Y;
Width=W;
buttonMode=true;
writeNormal();
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();
}
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);
}
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 TwoToggle extends Clickable {
private var val:int;
private var txt:TextField;
private var box:Sprite;
private var s1:String;
private var s2:String;
public function TwoToggle(ss1:String,ss2:String,L:int,Y:int,WW:int,c:int=0):void {
super(L,Y,WW);
s1=ss1; s2=ss2;
val=0;
box=new Sprite();
txt=new TextField();
txt.text=s1;
txt.height=18;
txt.x=16;
txt.width=Width-30;
txt.textColor=c;
txt.y=0;
addChild(txt);
addChild(box);
write();
}
public override function MUp(e:Event):void {
toggle();
update();
}
public function setValue(a:int):void {
val=a;
if( val==0 ) {
txt.text=s1;
} else if( val==1 ) {
txt.text=s2;
} else {
txt.text="Something wrong!";
}
}
public function value():int {
return val;
}
public function toggle():void {
val ++;
if( val >1 ) {val=0;}
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();
box.graphics.lineStyle(1,0x8800000);
box.graphics.beginFill(0xee0000);
box.graphics.moveTo(2,3);
box.graphics.lineTo(8,14);
box.graphics.lineTo(14,3);
box.graphics.endFill();
}
}
class PushButton extends Clickable{
private var txt:TextField;
private var label:String;
public function PushButton(L:int,Y:int,WW:int,l:String,c:int=0):void {
super(L,Y,WW);
label=l;
txt=new TextField();
txt.text=label;
txt.height=18;
txt.width=Width;
txt.x=2;
txt.textColor=c;
txt.y=0;
addChild(txt);
}
public override function MUp(e:Event):void {
dispatchEvent(new Event("allerase",true));
}
}
class Check extends Clickable {
private var val:Boolean;
private var txt:TextField;
private var label:String;
private var box:Sprite;
public function Check(now:Boolean,X:int,Y:int,W:int,l:String,c:int=0):void {
super(X,Y,W);
val=now;
label=l;
txt=new TextField();
txt.text=label;
txt.height=18;
txt.x=16;
txt.textColor=c;
txt.y=0;
addChild(txt);
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);
}
}
}