flash on 2014-10-7
♥0 |
Line 102 |
Modified 2014-10-07 05:31:19 |
MIT License
archived:2017-03-30 11:53:47
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/hopl
*/
package {
import flash.text.TextField;
import flash.utils.Dictionary;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
dictBtn = new Dictionary();
var i:int;
var a:xBtn;
for (i = 0; i < 8; i++)
{
a = new xBtn();
a.x = 16+i * 40;
a.y = 16;
a.id = i + 1;
a.ft = this;
a.cost = i*2;
addChild(a);
dictBtn[a.id] = a;
}//nexti
a = new xBtn();
a.x = 48;
a.y = 180;
a.id = 32;
a.ft = this;
addChild(a);
deb = new TextField();
deb.text = "x";
deb.x = 50;
deb.y= 100;
deb.mouseEnabled = false;
addChild(deb);
deb.text = cash+"$";
deb2 = new TextField();
deb2.text = "x"; deb2.x = 200; deb.y= 100;
deb2.mouseEnabled = false;
addChild(deb2);
}//ctor
public var dictBtn:Dictionary;
public var deb:TextField;
public var deb2:TextField;
public var cash:int = 6;
public function onOver(on:xBtn):void
{
deb2.visible = true;
deb2.text = on.cost+"$";
}//onover
public function onOut(on:xBtn):void
{
deb2.visible = false;
}//onout
public var cur:xBtn = null;
public function onClick(on:xBtn):void
{
//a.y += 20;
if (on.id == 32) { cash += 1; deb.text = cash+"$"; return; }
if (cur == null && on.cost > cash) { return; }
if (cur != null && (cur.cost + cash < on.cost)) { return; }
if (cur != null)
{ cash += cur.cost; }
var i:int;
var b:xBtn;
for (i = 0; i < 8; i++)
{
b = dictBtn[i+1]; if (b == null) { continue; }
b.y = 16;
if (b.id < on.id) { b.y += 10; }
//if (b.check > 0) { b.check = 0; cash += b.cost; }
}//nexti
on.y += 20;
on.check = 1;
cash -= on.cost;
cur = on;
//deb.text = ""+on.cost+"/"+cash;
deb.text = cash+"$";
}//click
}//classend
}
import flash.display.Sprite;
import flash.events.MouseEvent;
internal class xBtn extends Sprite
{
public var id:int = 0;
public var ft:FlashTest = null;
public var cost:int = 0;
public var check:int = 0;
public function xBtn()
{
graphics.clear();
graphics.lineStyle(2,0);
graphics.beginFill(0x808080,1);
graphics.drawRect(0,0,32,32);
graphics.endFill();
alpha = 0.5;
this.buttonMode = true;
this.useHandCursor = true;
addEventListener(MouseEvent.ROLL_OVER, rover);
addEventListener(MouseEvent.ROLL_OUT, rout);
addEventListener(MouseEvent.CLICK, click);
}//ctor
public function rover(e:MouseEvent):void { ft.onOver(this); alpha = 1; }
public function rout(e:MouseEvent):void { ft.onOut(this); alpha = 0.5; }
public function click(e:MouseEvent):void { ft.onClick(this); }
}//xbtn