flash on 2010-4-13
♥0 |
Line 64 |
Modified 2010-04-13 22:13:20 |
MIT License
archived:2017-03-30 02:24:17
ActionScript3 source code
/**
* Copyright kihon ( http://wonderfl.net/user/kihon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9CNF
*/
package
{
import com.bit101.components.Label;
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
public function Main()
{
var binary:Label = new Label(this, 157, 250, "binary - 0000");
var decimal:Label = new Label(this, 157, 270, "decimal - 0");
binary.scaleX = binary.scaleY = decimal.scaleX = decimal.scaleY = 2;
for (var i:int = 0; i < 4; i++)
{
var light:Light = new Light(Math.pow(2, 3 - i));
light.x = i * 35 + 169;
light.y = 232;
addChild(light);
light.addEventListener
(
Event.CHANGE,
function(event:Event):void
{
var num:String = Light.num.toString(2);
while (num.length < 4)
{
num = "0" + num;
}
binary.text = "binary - " + num;
decimal.text = "decimal - " + Light.num.toString();
}
);
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
class Light extends Sprite
{
public static var num:int = 15;
public var value:int;
public var on:Boolean = true;
public function Light(value:int)
{
this.value = value;
onMouseDown();
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
public function onMouseDown(event:MouseEvent = null):void
{
graphics.clear();
var matrix:Matrix = new Matrix();
matrix.createGradientBox(30, 30, 45 * Math.PI / 180, -15, -15);
if (on) graphics.beginGradientFill("linear", [0x0, 0x7F7F7F], [1.0, 1.0], [0, 255], matrix), num -= value;
else graphics.beginGradientFill("linear", [0xED1A3D, 0xFF9999], [1.0, 1.0], [0, 255], matrix), num += value;
graphics.drawCircle(0, 0, 15);
graphics.endFill();
on = !on;
dispatchEvent(new Event(Event.CHANGE));
}
}