Tapping and holding handler for flex button
在 iPod 與 iTune裏,forward/rewind button 通常有 2 種功能
-按一下就放開(tap):跳到下一首歌
-按者不放開(hold): 快速前進
一般在 flex 裏操作 Button 時大多是偵聽 click event,代表按鈕被 "按下" 然後 "放開",兩者是一體的,缺一不可,但也因此無法區分 tap or hold 的操作。
如果要區分上述兩種效果就必需要動點手腳,今天玩了一下找到了一個簡單又好用的解決方法。
這裏主要是在玩弄 Button 內建的兩個的 event
-buttonDown
-click
另外 buttonDown 還提供兩個參數 repeatDelay, repeatInterval 可更精準的控制 holding 的行為,真是非常貼心的設計。
Actionscript:
-
var first:Boolean = true;
-
var isHolding:Boolean = false;
-
-
function onDown(){
-
if(first){
-
first = false;
-
return;
-
}
-
//
-
trace("button holding down: ", getTimer() );
-
isHolding = true;
-
}
-
-
function onClick(){
-
if( !isHolding ){
-
trace("click and release, it's a tap");
-
}
-
first = true;
-
isHolding = false;
-
}
XML:
-
<mx :Button label="test"
-
buttonDown="onDown()" repeatDelay="200" repeatInterval="60"
-
click="onClick()" autoRepeat="true"
-
/>
by admin


1 Comment Add your own
1. Jove&hellip | May 1st, 2007 at 2:55 am
那个NumericStepper就是这样的,用了这个buttonDown
Trackback this post | Subscribe to the comments via RSS Feed