Pay for Hesitation: Double click in AS3

Pages

2008年4月1日 星期二

Double click in AS3

AS3開始支援直接加入double click事件了!然而, 這會造成一個問題, 當single click和double click兩個事件同時被觸發時, click事件會把double click擋掉, 因此如果希望將single和double click指定給interactiveObjectInstance看似不可行的. 不過, 有種方法可以解決, 只要我們在single click時設一個time interval, 如果在這個interval內沒有再次點擊, 就認定它為click事件, 否則就當成double click事件, 然後記得清除這個interval.
DEMO: http://140.112.31.185/flextest/clickDoubleClickIssue.swf
On click, in the click handler, reset and initiate the timer which on complete, calls the deferredClickHandler (where the actual clickHandler code sits) If doubleClick does not occur, the timer completes and then executes the deferredClickHandler (I have kept my timer to be 300 mS) If doubleClick occurs, it goes to the doubleClick handler, where you clear the timer (so that timer does not complete and execute the deferredClickHandler) and execute the doubleClickHandler code…

沒有留言: