-- EVENT BROKER -- -- Movie Script -- -- © April 2006, Fuel Industries -- -- ---------------------------------------------------------------------- -- 060428 JN: Added pCurrentEvent to allow an object to be -- deregistered for an event from a handler triggered by -- that event. -- 060423 JN: version 0.1 ---------------------------------------------------------------------- -- The purpose of the script is to allow objects to register for any -- of the followingmovie events: -- -- #startMovie -- #prepareFrame -- #enterFrame -- #idle -- #exitFrame -- #stopMovie -- -- #stepFrame -- -- #keyDown -- #keyUp -- #mouseDown -- #mouseEnter -- #mouseLeave -- #mouseUp -- #mouseUpOutside -- #mouseWithin -- #rightMouseDown -- #rightMouseUp -- #hyperlinkClicked -- -- #activateWindow -- #deactivateWindow -- #moveWindow -- #resizeWindow -- #zoomWindow -- -- #timeOut -- -- NOTE: This script does not handle the one-off #prepareMovie event, -- as this call may be required to set up other functionality, -- including the first call to this Broker. -- ---------------------------------------------------------------------- -- PERFORMANCE -- ----------- -- While all other movie-level events are catered for by this script, -- most of these have been commented out. For improved performance, -- only enable event handlers that objects will be registering for. -- -- This script should be the first movie script in a movie with -- handlers for any of the enabled movie events. -- ---------------------------------------------------------------------- -- SYNTAX -- ------ -- Objects register using the call: -- -- Event_Register(, {, option symbol}) -- -- The option symbol may be any of the following symbols: -- -- #once: the chosen event is sent to the object once only, -- then the object is de-registered -- #persistent: the object will continue to receive the event even if -- the playback head jumps to another movie -- #stop: de-registers the object from the given event -- ---------------------------------------------------------------------- -- DEPENDENCIES -- ------------ -- Requires the following scripts: -- * Get Handlers Movie Script -- for HasHandler() method -- * OneShot Event Parent Script -- required for #once option -- ---------------------------------------------------------------------- -- WATCHER EXPRESSIONS -- ------------------- -- script("Event Broker").broker.plRegistry[#enterFrame] ---------------------------------------------------------------------- --==================================================================-- on __PUBLIC_METHOD__ end --==============================================================-- on Event_Register(anEvent, anObject, anOption) ----------------------- -- INPUT: should be one of the movie events handled by -- this script -- should be an object with a handler for anEvent -- may be #once, #persistent or #stop. Other -- values will be ignored. -- ACTION: Registers (deregisters if anOption is #stop) the given -- object to receive the given event -- OUTPUT: Returns 0 for no error, or an error symbol. -------------------------------------------------------------------- vBroker = Event_GetBroker() return vBroker.mEvent_Register(anEvent, anObject, anOption) end Event_Register --==================================================================-- on __BROKER_METHOD__ AND_PROPERTY end --==============================================================-- property broker on Event_GetBroker(me) ------------------------------------------------ -- SOURCE: Called by all Public Methods except XtraInfo(), and sent -- to the actorList by mInitialize() -- ACTION: Creates an instance of this script, if none exists, and -- stores it as the .broker property of the script itself. -- OUTPUT: Returns a pointer to the .broker instance -------------------------------------------------------------------- if ilk(me) <> #instance then -- This call was received from a movie-level handler vScript = script("Event Broker") -- HARD-CODED script name vBroker = vScript.broker if voidP(vBroker) then vBroker = call(#Event_GetBroker, the actorList) if ilk(vBroker, #instance) then -- Use the instance on the actorList else -- Create a new instance vBroker = vScript.new() -- implicit handler vBroker.mInitialize() (the actorList).append(vBroker) end if vScript.broker = vBroker end if else -- This call was sent to the actorList by mInitialize() vBroker = me end if return vBroker end Event_GetBroker --==================================================================-- on __PRIVATE_METHODS__ AND_PROPERTIES end --==============================================================-- property plRegistry -- [#: [<0|#persistent>: ,...], -- ...] property pOneShotScript -- script("Event OneShot") property pCurrentEvent -- symbol event currently being forwarded | 0 on mInitialize(me) --------------------------------------------------- -- SOURCE: Sent by Event_GetBroker() -- ACTION: Creates an alphabetical list of names of all the -- available Lingo xtras as symbols (to avoid case- -- sensitivity) -------------------------------------------------------------------- vMember = member("Event OneShot") -- HARD-CODED name if ilk(vMember, #member) then if vMember.type = #script then pOneShotScript = script(vMember) if not pOneShotScript.handler(#mEvent_DeleteFromList) then -- The "Event OneShot" script appears to exist pOneShotScript = 0 end if end if end if if ilk(pOneShotScript) <> #script then vMessage = vMember&" could not be found."&RETURN&RETURN&\ "Calls to Event_Register with an option of #once will fail." xCeption(#event, vMessage) end if plRegistry = [:] plRegistry.sort() -- -- For improved performance, only uncomment events that objects -- -- will be registering for. You will also need to uncomment the -- -- relevant event handler below. -- plRegistry.addProp(#startMovie, [:]) -- plRegistry.addProp(#prepareFrame, [:]) plRegistry.addProp(#enterFrame, [:]) -- plRegistry.addProp(#idle, [:]) -- plRegistry.addProp(#exitFrame, [:]) plRegistry.addProp(#stopMovie, [:]) -- -- plRegistry.addProp(#stepFrame, [:]) -- -- plRegistry.addProp(#keyDown, [:]) -- plRegistry.addProp(#keyUp, [:]) -- plRegistry.addProp(#mouseDown, [:]) -- plRegistry.addProp(#mouseEnter, [:]) -- plRegistry.addProp(#mouseLeave, [:]) -- plRegistry.addProp(#mouseUp, [:]) -- plRegistry.addProp(#mouseUpOutside, [:]) -- plRegistry.addProp(#mouseWithin, [:]) -- plRegistry.addProp(#rightMouseDown, [:]) -- plRegistry.addProp(#rightMouseUp, [:]) -- plRegistry.addProp(#hyperlinkClicked, [:]) -- -- plRegistry.addProp(#activateWindow, [:]) -- plRegistry.addProp(#deactivateWindow, [:]) -- plRegistry.addProp(#moveWindow, [:]) -- plRegistry.addProp(#resizeWindow, [:]) -- plRegistry.addProp(#zoomWindow, [:]) -- -- plRegistry.addProp(#timeOut, [:]) pCurrentEvent = 0 end mInitialize on mEvent_Register(me, anEvent, anObject, anOption) ------------------ -- INPUT: should be one of the movie events handled by -- this script -- should be an script or script instance with a -- handler for anEvent -- may be #once, #persistent or #stop. -- (Other values will be ignored). -- ACTION: Registers (deregisters if anOption is #stop) the given -- object to receive the given event -- OUTPUT: Returns 0 for no error, or an error symbol. -------------------------------------------------------------------- if not plRegistry.findPos(anEvent) then return xCeption(#event, "The #"&anEvent&" event is not supported") end if vList = plRegistry[anEvent] if anOption = #stop then -- We can de-register an object, even if it is invalid if pCurrentEvent <> anEvent then -- Simply stop sending events to the given object vList.deleteOne(anObject) else -- anEvent is currently being call()ed on vList. We need to -- remove the given object from vList, and then ensure that the -- next item on the list receives anEvent vIndex = vList.getPos(anObject) if vIndex then vList.deleteAt(vIndex) if vIndex > vList.count then else vItem = vList[vIndex] call(anEvent, vItem) end if -- we deleted item at end of vList? end if -- anObject had previously been registered? end if -- anEvent is currently being broadcast? else -- We are attempting to register anObject. We must first check -- that it is a script or instance, and that it has a handler for -- the given event vIlk = ilk(anObject) case vIlk of #script: if not HasHandler(anObject, anEvent) then vMessage = "Event #"&anEvent&" not handled by "&anObject return xCeption(#event, vMessage) end if #instance: if string(anObject) starts " will be the symbol name of the event called -- ACTION: Forwards the event to all objects registered for it. -------------------------------------------------------------------- -- Store which event is currently being forwarded so that if an -- object de-registers for this event, we will know that the next -- object in the Registry event list needs to be sent the event -- manually. pCurrentEvent = anEvent vList = plRegistry[anEvent] -- [: , ...] call(anEvent, vList) -- If an object now asks to de-register anEvent, this will no -- longer interfere with the call() broadcast. pCurrentEvent = 0 end mEvent_Forward on mEvent_ClearNonPersistentObjects(me) ------------------------------ -- SOURCE: Sent by stopMovie() -- ACTION: Removes all objects whose property is not #persistent -- from the various plRegistry sublists when the movie -- stops. -------------------------------------------------------------------- repeat with vList in plRegistry i = vList.count repeat while i if not vList.getPropAt(i) then vList.deleteAt(i) end if i = i - 1 end repeat end repeat end mEvent_ClearNonPersistentObjects --==================================================================-- on __MOVIE_EVENTS__ -- For improved performance, only uncomment handlers for events that -- objects will be registering for. You will also need to uncomment -- the relevant entries for the plRegistry list in the mInitialize() -- handler above. end --==============================================================-- --on startMovie() ------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#startMovie) --end startMovie on stopMovie() ------------------------------------------------------- -- ACTION: Forwards the movie event to all registered objects -------------------------------------------------------------------- vBroker = Event_GetBroker() vBroker.mEvent_Forward(#stopMovie) -- Special case vBroker.mEvent_ClearNonPersistentObjects() end stopMovie --==================================================================-- on __FRAME_EVENTS__ end --==============================================================-- --on prepareFrame() ---------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#prepareFrame) --end prepareFrame -- -- -- --on stepFrame() ------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#stepFrame) --end stepFrame on enterFrame() ------------------------------------------------------ -- ACTION: Forwards the movie event to all registered objects -------------------------------------------------------------------- -- vTrace = the trace -- the trace = FALSE -- vMS = the milliseconds vBroker = Event_GetBroker() vBroker.mEvent_Forward(#enterFrame) -- vMS = the milliseconds - vMS -- put the frame, vMS -- the trace = vTrace end enterFrame --on idle() ------------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#idle) --end idle -- -- -- --on exitFrame() ------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#exitFrame) --end exitFrame -- -- -- --on timeOut() --------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#timeOut) --end timeOut -- -- -- -- --on __KEY_EVENTS__ -- --================================================================-- --end -- -- -- --on keyDown() --------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#keyDown) --end keyDown -- -- -- --on keyUp() ----------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#keyUp) --end keyUp -- -- -- -- --on __MOUSE_EVENTS__ -- --================================================================-- --end -- -- -- --on mouseDown() ------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseDown) --end mouseDown -- -- -- --on mouseEnter() ------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseEnter) --end mouseEnter -- -- -- --on mouseLeave() ------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseLeave) --end mouseLeave -- -- -- --on mouseUp() --------------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseUp) --end mouseUp -- -- -- --on mouseUpOutside() -------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseUpOutside) --end mouseUpOutside -- -- -- --on mouseWithin() ----------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#mouseWithin) --end mouseWithin -- -- -- --on rightMouseDown() -------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#rightMouseDown) --end rightMouseDown -- -- -- --on rightMouseUp() ---------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#rightMouseUp) --end rightMouseUp -- -- -- --on hyperlinkClicked() ------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#hyperlinkClicked) --end hyperlinkClicked -- -- -- -- --on __WINDOW_EVENTS__ -- --================================================================-- --end -- -- -- --on activateWindow() -------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#activateWindow) --end activateWindow -- -- -- --on deactivateWindow() ------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#deactivateWindow) --end deactivateWindow -- -- -- --on moveWindow() ------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#moveWindow) --end moveWindow -- -- -- --on resizeWindow() ---------------------------------------------------- -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#resizeWindow) --end resizeWindow -- -- -- --on zoomWindow() ------------------------------------------------------ -- -- ACTION: Forwards the movie event to all registered objects -- -------------------------------------------------------------------- -- -- vBroker = Event_GetBroker() -- vBroker.mEvent_Forward(#zoomWindow) --end zoomWindow --34567890123456789012345678901234567890123456789012345678901234567890