At 9:44 +1200 2001_07_05, Sean Wilson wrote:
>Let's assume we have a behavior that creates a timeout object.
And provides itself as the target object of the timer, as per Sean's
instructions?
Which is a sound concept because it is preferable to target messages
directly to given objects rather than merely yelling in the bush with
a movie-event.
But there is a catch.
Besides sending back the specified callbackHandler message,
timeOutObjects also send various movie-events back to the
target-object, including prepareFrame and exitFrame. Now if those
handlers are implemented in the behavior, which has become target, it
will receive double prepareFrame and exitFrame for each frame.
That could lead to nasty surprises, if "we" were caught unaware.
It can be argued, that a behavior targeted by a timeOutObject, is
less in need of having prepareFrame and exitFrame handlers, because
it has other means of receiving cyclic messages. So one solution,
when using behaviors and timeOutObjects, is to not implement those
cyclic handlers in the behavior.
As timeOutObject also supply themselves as a second parameter, when
messaging the target, we could also filter the messages in the
behavior, to see if they originate from the timeOutObject, or from
the score.
But my darling model, is to insert a helperObject between the
behavior and the timeOutObject.
I have a number of such "timeOutWrapperClasses" for different
purposes, that I almost always use as part of my framework. Here is
an example of a simple timeOutWrapperClass, which traps the movie
-events and score-events, so that the target object only receives the
#callBackHandler. It may itself look a bit complex, but you only need
to have one copy lying around, and its use is pretty transparent,
compared to ordinary timeOutObjects - see the example.
As an added bonus, this script also adds the ability to carry
parameters in the "timeOutObject".
-- TimeOutSimpleWrapperClass
-- Jakob Hede Madsen, <[EMAIL PROTECTED]>, May 23, 2001
property ancestor
property timeoutHandler
property target
property timeoutParam
on new me, aPeriod, aMethod, aObj, aParam
timeoutHandler = aMethod
target = aObj
timeoutParam = aParam
ancestor = timeOut(me.string).new(aPeriod, #mTimeOut, me)
return me
end
on forget me
call #forget, [ancestor]
ancestor = VOID
timeoutHandler = VOID
target = VOID
timeoutParam = VOID
end
on mTimeOut me
call timeoutHandler, [target], me, timeoutParam
end
--EXAMPLE
--property pTimer
--
--on beginSprite me
-- pTimer = script("TimeOutSimpleWrapperClass").new(250,
#mTimeoutCallBack, me, #testParam)
--end
--
--on endSprite me
-- pTimer.forget()
--end
--
--on mTimeoutCallBack me, aWrappedTimer, aParam
-- put #mCallBack, aParam
--end
--
--on exitFrame me
-- go the frame
--end
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/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!]