BitSwotch

by pasodania
♥0 | Line 47 | Modified 2009-12-16 14:41:12 | MIT License
play

ActionScript3 source code

/**
 * Copyright pasodania ( http://wonderfl.net/user/pasodania )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xzSM
 */

package {
	import flash.utils.SetIntervalTimer;
	import flash.text.engine.TextJustifier;
	import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
    		private var _bs:uint = 0x0000;
    		private var keta:String = "0000000000000000";
    		public var txt:TextField;
        public function FlashTest() {
            // write as3 code here..
            txt = new TextField();
            addChild(txt);
            txt.autoSize = "left";
            update();
            createSwitch();
        }
        
        public function createSwitch():void{
        		for(var i:int = 0; i < keta.length; i++){
        			var sp:Sprite = new Sprite();
        			with(sp.graphics){
        				beginFill(0xFFFFFF);
        				lineStyle(1, 0x000000);
        				drawRect(0, 0, 30, 30);
        				endFill();
        			}
        			var a:Array = [0,0,0,0,
        			               0,0,0,0,
        			               0,0,0,0,
        			               0,0,0,0];
        			a[i] = 1;
        			var t:String = a.join("");
        			sp.name = t;
        			addChild(sp);
        			
        			
        			sp.x = 30 + 30*(i%4);
        			sp.y = 30 + 30*int(i/4);
        			sp.addEventListener( MouseEvent.CLICK, function(e:MouseEvent):void{
        				_bs = _bs ^ parseInt(Sprite(e.target).name, 16);
        				update();
        			}, false, 0 ,true);
        		}
        }
        
        public function update():void{
        		txt.text = keta.substr(0, keta.length - _bs.toString(2).length) + _bs.toString(2);
        		
        }
    }
}