ボタンいっぱい

by matubo
♥0 | Line 34 | Modified 2009-10-11 15:15:04 | MIT License
play

ActionScript3 source code

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

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
  <mx:Script>
    <![CDATA[
      import mx.controls.Button;
      private var j:uint = 0;
    
      private function makeButton(add:uint):void {
        var manyButton:Button;
        var k:int;
        for(var i:int=1; i<=add; i++){
          k = i + j;
          manyButton = new Button();
          
          manyButton.x = 60*((k - 1) % 5);
          manyButton.y = 30*Math.ceil(k/5);
          manyButton.width = 50;
          manyButton.height = 20;
          manyButton.name = "m_"+k;          
          manyButton.label = "+"+k;
          manyButton.addEventListener(
            MouseEvent.CLICK, 
            function(event:MouseEvent):void{
              makeButton(aPanel.getChildIndex(DisplayObject(event.target)) + 1);
            }
          );
          aPanel.addChild(manyButton);
        }
        j = k;
      }
    ]]>
  </mx:Script>
  <mx:Button label="とりあえず30個" click="makeButton(30)" />
  <mx:Button label="削除" click="aPanel.removeAllChildren(); j=0;" />
  <mx:Panel id="aPanel" width="100%" height="100%" layout="absolute"/>
</mx:Application>