티스토리 뷰

Programming/Flex

Flex - Button

파란크리스마스 2007. 8. 14. 15:22
728x90

- 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>

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함