Flex - Button

Programming/Flex 2007.08.14 15:22 Posted by 파란크리스마스

- Click Event

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

 <mx:Script>
  <![CDATA[

    private function on_ButtonClick(event:Event):void {
    mx.controls.Alert.show(
     event.type  // click
     + "\n" + event.currentTarget.name  // Button1
     + "\n" + Button(event.currentTarget).label  // ButtonLabel
     + "\n" + event.toString()  // [MouseEvent type="click" bubbles=true cancelable=false eventPhase=2 localX=63 localY=12 stageX=73 stageY=22 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0]
    );  
    }  
   ]]>
  </mx:Script>

 <mx:Button x="10" y="10" label="ButtonLabel" click="on_ButtonClick(event)" id="Button1"/>
 
</mx:Application>

- Create Button


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

 <mx:Script>
  <![CDATA[

    private function on_ButtonClick(event:Event):void {
     
     var array_num:Array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"];
     var base_x:int = 10;
     var base_y:int = 90;
     var button_width:int = 30;
     var button_height:int = 45;
     
     for (var i:int = 0; i<4; i++) {
      for (var j:int = 0; j<3; j++) {
           var button:Button = new Button();
           button.label = array_num[ (i * 3) + j ];
           button.x = base_x + (j * button_width);
            button.y = base_y + (i * button_height);
            button.width = button_width;
            button.height = button_height;
            button.setStyle("fontSize", 14);
            this.addChild(button);
            button.addEventListener(MouseEvent.CLICK, clickHandler);
      }     
     }
    }  
   
    private function clickHandler(event:MouseEvent):void{
     Text1.text = Text1.text + Button(event.currentTarget).label;
    }     
   ]]>
  </mx:Script>

 <mx:Button x="10" y="10" label="Create Button" click="on_ButtonClick(event)" id="Button1" />
 <mx:TextArea x="10" y="40" id="Text1" fontSize="14"/>
 
</mx:Application>

신고


 

티스토리 툴바