Tapping and holding handler for flex button

In flex   April 30, 2007 - 9:54 am

在 iPod 與 iTune裏,forward/rewind button 通常有 2 種功能

-按一下就放開(tap):跳到下一首歌
-按者不放開(hold): 快速前進

一般在 flex 裏操作 Button 時大多是偵聽 click event,代表按鈕被 "按下" 然後 "放開",兩者是一體的,缺一不可,但也因此無法區分 tap or hold 的操作。

如果要區分上述兩種效果就必需要動點手腳,今天玩了一下找到了一個簡單又好用的解決方法。

這裏主要是在玩弄 Button 內建的兩個的 event
-buttonDown
-click

另外 buttonDown 還提供兩個參數 repeatDelay, repeatInterval 可更精準的控制 holding 的行為,真是非常貼心的設計。

Actionscript:
  1. var first:Boolean = true;
  2. var isHolding:Boolean = false;
  3.  
  4. function onDown(){
  5.     if(first){
  6.         first = false;
  7.         return;
  8.     }
  9.     //
  10.     trace("button holding down: ", getTimer() );
  11.     isHolding = true;
  12. }
  13.  
  14. function onClick(){
  15.     if( !isHolding ){
  16.         trace("click and release, it's a tap");
  17.     }
  18.     first = true;
  19.     isHolding = false;
  20. }

XML:
  1. <mx :Button label="test"
  2. buttonDown="onDown()" repeatDelay="200" repeatInterval="60"
  3. click="onClick()" autoRepeat="true"
  4.  />

by admin

1 Comment Add your own

  • 1. Jove&hellip  |  May 1st, 2007 at 2:55 am

    那个NumericStepper就是这样的,用了这个buttonDown

留言回應

hidden

您的留言會先經過站長認証後才刊登在網站上。
your comments will be approved by Administrator before appearing on the page.

Trackback this post  |  Subscribe to the comments via RSS Feed

mobile phone