Articles Archive
Articles Search
Director Wiki

Capturing Double Clicks with Lingo

December 6, 2000
by Gary Rosenzweig

A funny thing happened while writing this Lingo Lounge column. It was, and is, to be about capturing double clicks on buttons. I was going to start by explaining how the old Lingo property the doubleClick doesn't really work, because it simply returns TRUE if the last two clicks were within a certain time span, regardless of whether the two clicks occurred on the same object. This is on my list of annoying stuff that I hate about Director. You can click once on the Stage, and then again on a button, and the doubleClick will return TRUE. This, of course, is wrong. A double click should only register if the same object is clicked twice, rapidly. Over the years, this bug has forced me to always write my own behaviors to capture double clicks rather than using the doubleClick.

Here's the funny thing: this only happens on the Mac. Since I develop on the Mac, I have always seen it. However, when I tested the following movies on my Windows machine, both in Director and in Shockwave, the doubleClick worked properly. I don't know if this is a recent fix in Director 8, or it has always been this way. Anyway, my point is still valid since most of us develop for both platforms, especially when it comes to Shockwave. You can't rely on the doubleClick to capture real double clicks.

Let me demonstrate, keeping in mind that you will have to use Shockwave or Director for Mac to see the erroneous behavior. The following movie has two buttons. If you click on either one, the time (in milliseconds) appears below it. If you double click on one, you can see the value of the doubleClick appear in the text field above the buttons.

Now, if you are using a Mac, you can click rapidly once on the Stage and then again on a button. The value of the doubleClick will change to "1"! You can even click rapidly on one button and then the other to get the doubleClick to show "1". Fixing this is not hard, but you have to throw away the doubleClick altogether. Here is a behavior that uses Lingo to capture double clicks. Since the behavior instance belongs to the control, in this case a button, it will only detect double clicks where both clicks are on that button.

property pFirstClickTime

on beginSprite me
  pFirstClickTime = 0

on mouseDown me

  if pFirstClickTime > the milliseconds - 500 then
    -- this click came less than a half a second
    -- after the last click
    pFirstClickTime = 0
    -- only a single click, but record time
    -- because this could be the first half
    -- of a double click
    pFirstClickTime = the milliseconds
  end if


on singleClick me
  member("button 1 status").text = "Single"

on doubleClick me
  member("button 1 status").text = "Double"

Here is a sample movie that uses this behavior on one button, and a simpler behavior with the doubleClick on the other. The behavior is on the button to the left. If you play with it, you can see that there is no way to signal a double click other than double clicking on that button. The button to the right, however, can be made to show a double click by clicking elsewhere first, and then quickly clicking the button. This only happens on Macs, remember.

Two sample Director 8 movies are available for download in Mac or Windows format.

This behavior also allows you to have more control over the clicking. For instance, you could expand the amount of time allowed for a double click from half a second to a whole second. Or, you could modify this code to look for shift-double-clicks, or triple clicks. To some Director developers, minor details like this may seem like they are not worth worrying about. However, user interface standards are pretty well established between the makers of the operating systems and the makers of professional software. Elements like scrolling areas, buttons, menus, and so on need to work like they do in other pieces of software. If they do not, it only makes your Director projects look less professional.

Gary Rosenzweig's two most recent books are: "Special Edition Using Director 8" -- The most comprehensive guide to Director ever, including tons of examples and demo movies. It's suitable for novices and experts alike. "Advanced Lingo for Games" -- How to make games with Director 7 and 8. This book comes complete with full source code for more than 20 complete games. More information about these books can be found at They can be purchased there, or in your local bookstore.

Gary Rosenzweig is the Chief Engineer, founder, and owner of CleverMedia, a game and multimedia development company in Denver, Colorado. He is the author of ten books on Macromedia Director and Flash, including his latest, Special Edition Using Director MX.

Copyright 1997-2019, Director Online. Article content copyright by respective authors.