-- TAB -- -- -- © March 2004, OpenSpark Interactive Ltd -- -- ---------------------------------------------------------------------- -- This behavior should be used with a number of bitmap sprites shaped -- like tabs. The tab itself should be the same color as the -- background, with an outline lighter than the background and a long -- horizontal line. Each tab should be placed in a different position -- along the line: -- -- --------- -- _| Tab one |____________________________________ -- -- --------- -- ____________| Tab two |_________________________ -- -- --------- -- _______________________|Tab three|______________ -- -- When the user clicks on a tab, the playback head will jump to the -- marker with the same name as the bitmap member used for the tab. -- If there is no such marker, then nothing will happen. ---------------------------------------------------------------------- -- PROPERTY DECLARATIONS -- property spriteNum -- sprite channel property pSprite -- sprite(spriteNum) property pFrame -- marker(pSprite.member.name) Playback head -- jumps to this frame on mouseUp property ourTabList -- list of Tab behavior instances, shared between -- those instance. Instances appear in the order -- of their spriteNums, so the last instance has -- the highest spriteNum -- EVENT HANDLERS -- on beginSprite(me) --------------------------------------------------- -- ACTION: Sets the target frame --------------------------------------------------------------------- pSprite = sprite(spriteNum) -- Use #matte ink so that tab sprites in lower channels can be -- clicked pSprite.ink = 8 -- Adopt the name of the member as the target marker name pFrame = marker(pSprite.member.name) end beginSprite on endSprite(me) ----------------------------------------------------- -- ACTION: Removes circular references so that ourTabList can be -- cleared from memory --------------------------------------------------------------------- ourTabList.deleteOne(me) end endSprite on mouseUp(me) ------------------------------------------------------- -- ACTION: Shows this sprite in front of all other sprites with the -- same behavior, and jump to the associated frame. --------------------------------------------------------------------- if not ourTabList then -- Find all other sprites with this behavior. The last behavior -- in ourTabList will have the highest spriteNum. ourTabList = [] sendAllSprites(#Tab_SetList, ourTabList) end if -- Tell the other Tab instances to return to their proper channel... call(#resetLocZ, ourTabList) -- ... then place this sprite in front of all the others tLocZ = ourTabList.getLast().spriteNum + 1 pSprite.locZ = tLocZ -- Jump to marker with the same name as the member of this sprite if pFrame then go pFrame end if end mouseUp -- PUBLIC METHODS -- on Tab_SetList(me, aList) -------------------------------------------- -- SENT TO all sprites by mouseUp() the first time one of the Tab -- sprites is clicked -- INPUT: will be a linear list (of Tab instances) -- ACTION: Adopts aList as ourTabList, and adds a pointer to this -- instance to it. Each instance of this behavior will -- share a pointer to this unique list. -------------------------------------------------------------------- ourTabList = aList ourTabList.append(me) end Tab_SetList on ResetLocZ(me) ----------------------------------------------------- -- SENT TO all instances of this behavior in ourTabList when the -- user clicks on one of the tab sprites -- ACTION: The frontmost tab will have a locZ greater than its -- spriteNum. That tab will return to the locZ set for it -- by the score. -------------------------------------------------------------------- pSprite.locZ = spriteNum end ResetLocZ