トランプ

by pasodania
♥0 | Line 65 | Modified 2010-03-31 12:59:33 | 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/gpAy
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.display.Shape;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
    	
    		private var txt:TextField;
    		private var txt2:TextField;
    		private var answer:TextField;
    	
        public function FlashTest() {
            // write as3 code here..
            answer = new TextField();
            answer.autoSize = "left";
            answer.border = true;
            answer.selectable = false;
            answer.x = 10;
            answer.y = 100;
            answer.text = "result";
            addChild(answer);
            
            txt = new TextField();
            txt.x = 10;
            txt.y = 10;
            txt.width = 20;
            txt.height = 20;
            txt.type = "input";
            txt.border = true;
            txt.text = "3";
            addChild(txt);
            
            txt2 = new TextField();
            txt2.x = 40;
            txt2.y = 10;
            txt2.width = 100;
            txt2.height = 20;
            txt2.type = "input";
            txt2.border = true;
            txt2.text = "123123123";
            addChild(txt2);
            
            var btn:Sprite = new Sprite();
            btn.graphics.beginFill(0xFFFFFF);
            btn.graphics.lineStyle(3,0);
            btn.graphics.drawRect(0, 0, 50, 20);
            btn.graphics.endFill();
            btn.x = 150;
            btn.y = 10;
            btn.buttonMode = true;
            addChild(btn);
            
            btn.addEventListener( MouseEvent.CLICK, trump);
        }
        
        private function trump(e:MouseEvent):void{
        		answer.text = "{";
        		var num:int = int(txt.text);
			var cards:Array = String(txt2.text.toString()).split("");
			var len:int = cards.length - (cards.length%num);
			var result:Array = [];
			if( num > len ){
				result = new Array(num);
			} else {
				for( var i:int = 0 ; i < len ; i++ ){
					if( result[i%num] == undefined ) result[i%num] = "";
					result[i%num] += String(cards[i]);
				}
			}
    			answer.appendText('"' + result.join('","') + '"}');    	
        }
    }
}