Flex中如何通过doubleClickEnabled属性监听按钮(Button)doubleClick的例子

By Minidxer | January 1, 2009

接下来的例子演示了Flex中如何通过doubleClickEnabled属性,监听按钮(Button)doubleClick。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             private function button_click(evt:MouseEvent):void {
  10.                 appendText(evt.type);
  11.             }
  12.  
  13.             private function button_doubleClick(evt:MouseEvent):void {
  14.                 appendText(evt.type);
  15.             }
  16.  
  17.             private function appendText(str:String):void {
  18.                 var now:Date = new Date();
  19.                 textArea.text += "[" + now.toTimeString() + "] " + str + "\n";
  20.                 textArea.validateNow();
  21.                 textArea.verticalScrollPosition = textArea.maxVerticalScrollPosition;
  22.             }
  23.         ]]>
  24.     </mx:Script>
  25.  
  26.     <mx:ApplicationControlBar dock="true">
  27.         <mx:Form styleName="plain">
  28.             <mx:FormItem label="doubleClickEnabled:">
  29.                 <mx:CheckBox id="checkBox"
  30.                         selected="true" />
  31.             </mx:FormItem>
  32.             <mx:FormItem>
  33.                 <mx:Button id="button"
  34.                         label="[double] click me"
  35.                         doubleClickEnabled="{checkBox.selected}"
  36.                         click="button_click(event);"
  37.                         doubleClick="button_doubleClick(event);" />
  38.             </mx:FormItem>
  39.         </mx:Form>
  40.     </mx:ApplicationControlBar>
  41.  
  42.     <mx:TextArea id="textArea"
  43.             editable="false"
  44.             width="50%"
  45.             height="100%" />
  46.  
  47. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Button | No Comments » | Tags: , , ,

Search Posts