Director Web : Tips n' Scripts : OOPs

Double Click Handlers with Parent/Child Scripts

Date:    Wed, 27 Sep 1995 05:39:53 -0500
From:    "Glenn M. Picher" <gpicher@maine.com>
Subject: double click handlers (solves: order the effects of updatestage)
The following general-purpose cast script mouse handlers broaden the conceptual possibilities for double-click handling in Lingo. They are not rigorously tested, but they seem to work for me. On any problems, I'd greatly appreciate a report of some kind. They use parent/child programming techniques but you don't really need to understand how. Just modify the "on singleMouseDown", "on singleMouseUp", "on doubleMouseDown" and "on doubleMouseUp" handlers as needed.


global doubleClickObject
property wasDouble

on birth me
  set the wasDouble of me to 0
  return me
end

on mouseDown me, wasQueued, queuedUp
  if not voidP(wasQueued) then
    --The mouseDown event has gotten here via a time out,
    --not an actual click. Stop the time out clock.
    set the timeOutScript to ""
    set the timeOutLength to  10800
    --code for single click's mouseDown goes here...
    singleMouseDown()
    --end code for single click's mouseDown
    --dispatch the mouseUp again if necessary for a single click
    if not voidP(queuedUp) then
      set the wasDouble of doubleClickObject to 0
      mouseUp(doubleClickObject)
      return
    end if
  end if
  if the timeOutScript = "" then
    --queue the event, waiting for a time out
    set doubleClickObject to birth(script (the castnum of sprite (the clickOn)))
    set the timeOutLength to 30
    set the timeOutScript to "mouseDown(doubleClickObject,1)"
    return
  end if
  set the timeOutScript to ""
  set the timeOutLength to 10800
  set the wasDouble of doubleClickObject to 1
  --code for double click's mouseDown goes here...
  doubleMouseDown()
  --end code for double click's mouseDown
end

on mouseUp me
  if the timeOutScript = "mouseDown(doubleClickObject,1)" then
    set the timeOutScript to "mouseDown(doubleClickObject,1,1)"
    return
  end if
  if the wasDouble of doubleClickObject = 0 then
    --code for single click's mouse up goes here...
    singleMouseUp()
    --end code for single click's mouse up...
    return
  end if
  set the wasDouble of doubleClickObject to 0
  --code for double click's mouseUp goes here...
  doubleMouseUp()
  --end code for double click's mouse up...
end


--customizable handlers

on singleMouseDown
  put "single" into field "down status"
  updateStage
end

on singleMouseUp
  put "single" into field "up status"
  updateStage
end

on doubleMouseDown
  put "double" into field "down status"
  updateStage
end

on doubleMouseUp
  put "double" into field "up status"
  updateStage
end

This approach would allow you to implement radically different visual appearances and behaviors based on the type of click. Tim Fullerton, for instance, could update whatever sprites and play whatever sound necessary within the customizable handlers.

Caveats: