Hi

I believe I have used something written by Kerry that allowed callbacks or parameters for timeouts...a sort of timeout wrapper class that worked rather well as I recall...might be worth a dig in the archives, cause unfortunately I can't find the link right now....

I'm sorry I've missed this thread (indeed I miss a lots of things right now, swamped in damn work), anyway, here comes a parent script to wrap timeout objects and do a nice cleaning. The original script is from Jakob Hede Madsen, then modified by James Newton, then adapted to fit my needs.


The nice thing of these wrappers is that their properties have the same names than timeout objects properties, so you can still do oTimeOut.target = ... , or oTimeout.period = ...

Below you'll found a very little script to make things even simpler

Hope this helps
s�b


====== Parent script : 'timeoutWrapper' ========================== -- TIMEOUT WRAPPER (PARENT SCRIPT) -- -- -- Use this parent script to create a timeout which calls back with -- a chosen parameter. #prepareFrame, #stopMovie and other handlers -- called by timeOut objects are not handled. -- -- Syntax: -- pTimeOut=script("timeoutOnceWrapper").new(1000, #callback, me, <data>) -- -- If the target is a Movie Script, the following syntax will work -- just as well: -- -- timeOut("name").new(1000, #callback, <data>)



-- PUBLIC PROPERTIES --
property timeoutHandler -- Handler called to target at timeoutEvents
property target         -- The "client" object [pCallbackObject]

-- PRIVATE PROPERTIES --
property ancestor       -- the actual timeoutObject
property pParameter     -- parameter passed as argument when calling
--                         back to target.
property pParam2, pParam3



-- PUBLIC METHODS --

on new(me, aPeriod, aHandler, aTarget, aParameter, aParam2, aParam3)--
  --                                                            PUBLIC
  --
  -- INPUT:
  -- Standard timeOut inputs:
  -- <aPeriod>  integer number of milliseconds
  -- <aHandler> symbol callback handler
  -- <aTarget>  script | instance : object containing callback handler
  --
  --
  -- Additional wrapper class input:
  -- <aParameter> parameter passed as argument when calling back to
  --              target.
  --
  -- ACTION: Instanciates timeOut object ancestor, and prepares this
  -- wrapper instance for work.
  -------

  -- Set up timeOut object
  ancestor       = timeOut(me.string).new(aPeriod, #mTimeOut, me)

  -- Make this wrapper mimic the properties of the timeOut object
  timeoutHandler = aHandler
  target         = aTarget
  if not listP(target) then target = [aTarget]

  pParameter = aParameter
  pParam2 = aParam2
  pParam3 = aParam3

  return me
end -- new


on mKill (me) -------------------------------------------------------- -- PUBLIC ALIAS

  me.forget()
end


on forget(me) -------------------------------------------------------- -- PUBLIC -- ACTION: Mimics the timeOut object's own forget() method and -- ensures that no circular references are left dangling. -------

  if not voidP(ancestor) then
    ancestor.target = VOID
    ancestor.forget()
    ancestor   = VOID
    target.deleteAll()
    target     = VOID
    pParameter = VOID
  end if
end -- forget




-- PRIVATE METHOD --


on mTimeOut(me, aTimeOut) ---------------------------------------------
  -- Called by the timeOut object ancestor at regular intervals
  --
  -- ACTION: calls the target object with the chosen parameter
  -------

  call(timeoutHandler, target, pParameter, pParam2, pParam3)
end -- mTimeOut


====== Parent script : 'timeoutOnceWrapper' =========================
This is a little variation of the aboce, for the many cases when you don't want a timeout to call a callback many time, but just do a simple delayed action.



-- TIMEOUT(once) WRAPPER (PARENT SCRIPT) -- -- -- Use this parent script to create a timeout which calls back with -- a chosen parameter. #prepareFrame, #stopMovie and other handlers -- called by timeOut objects are not handled. -- -- Syntax: -- pTimeOut=script("timeoutOnceWrapper").new(1000, #callback, me, <data>) -- -- If the target is a Movie Script, the following syntax will work -- just as well: -- -- timeOut("name").new(1000, #callback, <data>)



-- PUBLIC PROPERTIES --
property timeoutHandler -- Handler called to target at timeoutEvents
property target         -- The "client" object [pCallbackObject]

-- PRIVATE PROPERTIES --
property ancestor       -- the actual timeoutObject
property pParameter     -- parameter passed as argument when calling
--                         back to target.
property pParam2, pParam3



-- PUBLIC METHODS --

on new(me, aPeriod, aHandler, aTarget, aParameter, aParam2, aParam3)--
  -- INPUT:
  -- Standard timeOut inputs:
  -- <aPeriod>  integer number of milliseconds
  -- <aHandler> symbol callback handler
  -- <aTarget>  script | instance : object containing callback handler
  --
  --
  -- Additional wrapper class input:
  -- <aParameter> parameter passed as argument when calling back to
  --              target.
  --
  -- ACTION: Instanciates timeOut object ancestor, and prepares this
  -- wrapper instance for work.
  -------

  -- Set up timeOut object
  ancestor       = timeOut(me.string).new(aPeriod, #mTimeOut, me)

  -- Make this wrapper mimic the properties of the timeOut object
  timeoutHandler = aHandler
  target         = aTarget
  if not listP(target) then target = [aTarget]

  pParameter = aParameter
  pParam2 = aParam2
  pParam3 = aParam3

  return me
end -- new


on mKill (me) me.forget() end

on forget(me) --------------------------------------------------------
  -- ACTION: Mimics the timeOut object's own forget() method and
  -- ensures that no circular references are left dangling.
  -------

  if not voidP(ancestor) then
    ancestor.target = VOID
    ancestor.forget()
    ancestor   = VOID
    target.deleteAll()
    target     = VOID
    pParameter = VOID
  end if
end -- forget




-- PRIVATE METHOD --


on mTimeOut(me, aTimeOut) ---------------------------------------------
  -- Called by the timeOut object ancestor at regular intervals
  --
  -- ACTION: calls the target object with the chosen parameter
  -------

  call(timeoutHandler, target, pParameter, pParam2, pParam3)
  me.forget()
end -- mTimeOut


===== movie script for easier timeout wrapping =======================


on _Timeout (nDelay, yCallBack, oTarget, aArg1, aArg2, aArg3) --------
  --
  -- INPUT:
  -- Standard timeOut inputs:
  -- <nDelay>  integer number of milliseconds
  -- <yCallBack> symbol callback handler
  -- <oTarget>  script | instance : object containing callback handler
  --
  --
  -- Additional wrapper class input:
  -- <aArg1, aArg2, aArg3> parameters passed as argument when calling
  --              back to target.
  --
  -- ACTION: Instanciates timeOut object ancestor, and prepares this
  -- wrapper instance for work.
  -------

  scT = script("timeoutWrapper")
  return scT.new(nDelay, yCallBack, oTarget, aArg1, aArg2, aArg3)
end -- TimeoutOnce handler


[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to