flash on 2014-12-1
♥0 |
Line 102 |
Modified 2014-12-01 02:05:15 |
MIT License
archived:2017-03-30 11:52:07
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/qfGA
*/
package {
import flash.events.MouseEvent;
import flash.utils.Dictionary;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
vecRect = new Vector.<xRect>(0,false);
dictRect = new Dictionary();
var a:xRect;
a = new xRect();
a.cx = 32; a.cy = 32; a.id = 10;
a.unlocked = 0;
addRect(a);
a = new xRect();
a.cx = 32; a.cy = 132; a.id = 20; a.prev=10;
addRect(a);
a = new xRect();
a.cx = 300; a.cy = 128; a.id = 120;
addRect(a);
a = new xRect();
a.cx = 132; a.cy = 32; a.id = 30; a.prev=10;
addRect(a);
a = new xRect();
a.cx = 132; a.cy = 232; a.id = 40; a.prev=30;
addRect(a);
a = new xRect();
a.cx = 132; a.cy = 232+64; a.id = 50; a.prev=40;
addRect(a);
a = new xRect();
a.cx = 132+64; a.cy = 232; a.id = 60; a.prev=40;
addRect(a);
stage.addEventListener(MouseEvent.CLICK, onClick);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public function onClick(e:MouseEvent):void
{ mclick = 1; }
public function addRect(a:xRect):void
{
vecRect.push(a);
dictRect[a.id] = a;
}//addrect
public var mclick:int = 0;
public var vecRect:Vector.<xRect>;
public var dictRect:Dictionary;
public function isOver(a:xRect, ax:Number, ay:Number):Boolean
{
if (ax < a.cx) { return false; }
if (ay < a.cy) {return false; }
if (ax > a.cx+48) {return false;}
if (ay > a.cy+48) {return false;}
return true;
}//isover
public function onEnter(e:Event):void
{
var mx:Number; var my:Number;
mx = stage.mouseX; my = stage.mouseY;
graphics.clear();
graphics.lineStyle(2,0);
var i:int; var num:int; var a:xRect; var b:xRect;
num = vecRect.length;
for (i = 0; i < num; i++)
{
a = vecRect[i];
b = dictRect[a.prev];
if (b != null)
{
graphics.moveTo(b.cx+24,b.cy+24);
graphics.lineTo(a.cx+24,a.cy+24);
}//endif
graphics.drawRect(a.cx,a.cy, 48,48);
var w:Boolean;
w = ( (b == null) || ( b!= null && b.unlocked ) ) && a.unlocked <=0;
if (a.unlocked <= 0)
{
graphics.beginFill(0, w ? 0.5: 1);
graphics.drawRect(a.cx,a.cy, 48,48);
graphics.endFill();
}//endif
if (isOver(a,mx,my))
{
graphics.beginFill(0xFF, 0.2);
graphics.drawRect(a.cx,a.cy, 48,48);
graphics.endFill();
if (w && mclick)
{
a.unlocked = 1;
//a.cx+=4; a.cy+=4; //debug
}//endif2
}//endif
}//nexti
mclick = 0;
}//onenter
}//classend
}
internal class xRect
{
public var cx:Number = 0;
public var cy:Number = 0;
public var unlocked:int = 0;
public var id:int = 0;
public var prev:int = 0;
}//xrect