FLEX4_Label與Button建立Click 事件判斷範例



  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  3.   xmlns:s="library://ns.adobe.com/flex/spark" 
  4.   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
  5.   initialize="init()">
  6. <fx:Declarations>
  7. <!-- Place non-visual elements (e.g., services, value objects) here -->
  8. </fx:Declarations>
  9. <fx:Script>
  10. <![CDATA[
  11. private function init():void{
  12. button3.addEventListener(MouseEvent.CLICK , handleClick);
  13. }
  14. private function handleClick(event:MouseEvent):void{
  15. if(event.target==button2){
  16. label.text+='Button 2 clicked\n';
  17. }
  18. else if(event.target==button3){
  19. label.text+='Button 3 clicked\n';
  20. }
  21. }
  22. ]]>
  23. </fx:Script>
  24. <s:VGroup x="0" y="0" width="100%">
  25. <s:Button id="button1" x="198" y="223" label="Button 1" click="label.text+='Button 1 clicked\n'"/>
  26. <s:Button id="button2" x="336" y="223" label="Button 2" click="handleClick(event)"/>
  27. <s:Button id="button3" x="482" y="223" label="Button 3"/>
  28. <s:Label  id="label"/>
  29. </s:VGroup>
  30. </s:Application>





       初始化事件分有:initialize、creationComplete、applicationComplete  

顯示結果:

按下Button 1會顯示 Button 1,Button 2會顯示 Button 2,Button 3會顯示 Button 3,並且會累加下去。

留言

這個網誌中的熱門文章

如何使用Windows Server 2012 R2 DNS伺服器中的設定與網域名稱與IP綁定對應

使用Windows Server 2012 R2 來建立 Active Directory(AD) 使用者帳號與群組

使用Windows Server 2012 R2 來建立 Active Directory(AD) 來管理使用者帳戶以一台Win7為例