flash on 2016-2-1
♥0 |
Line 65 |
Modified 2016-02-01 08:02:22 |
MIT License
archived:2017-03-30 11:40:10
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/E6dZ
*/
package {
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.width=320; deb.height=240;
deb.mouseEnabled=false;
deb.text ="xx";
addChild(deb);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMup);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public function onMdown(e:MouseEvent):void { mbutton = 1; }
public function onMup(e:MouseEvent):void { mbutton = 0; }
public function onEnter(e:Event):void
{
mx = stage.mouseX;
my = stage.mouseY;
reset();
graphics.clear();
graphics.lineStyle(2, 0);
//drawBtn(10, 32,32, 32,32);
var m:int; m = 10;
var i:int; var k:int;
for (i=0;i<8;i+=1)
{ for (k =0;k<8;k+=1)
{
drawBtn(m, 32+k*32,32+i*32, 32,32);
m+=1;
}//nextk
}//nexti
// deb.text=""+mbutton;
if (btnPush > 0)
{ deb.text = ""+btnPush; }
}//onenter
public var deb:TextField;
public var mx:Number = 0;
public var my:Number = 0;
public var mbutton:int = 0;
public var btnOver:int = -1;
public var btnDown:int = -1;
public var btnPush:int = -1;
public function reset():void
{ if (mbutton<=0 && (btnPush>0 || btnOver!=btnDown))
{ btnDown = -1; }
btnPush = -1; btnOver = -1;
}//reset
public function drawBtn(id:int, ax:Number,ay:Number,aw:Number,ah:Number):void
{ var over:Boolean;
over = (mx < ax || my < ay || mx > ax + aw || my > ay + ah) == false;
if (over) { btnOver = id; }
if (mbutton > 0 && btnDown < 0 && over) { btnDown = id; }
if (over && btnDown == id && mbutton <= 0) { btnPush = id; btnDown = -1; }
if (over) { ax+=1; ay+=1; }
if (over && btnDown==id) { ax +=2; ay+=2; }
graphics.drawRect(ax,ay,aw,ah);
if (btnDown==id)
{ graphics.beginFill(over?0x008000:0x808080,1);
graphics.drawRect(ax,ay,aw,ah);
graphics.endFill(); }
}//drawbtn
}//classend
}