-- GO MOVIE BUTTON -- -- -- © July 2000, James Newton -- PROPERTIES -- -- author-defined parameters: property targetMovie -- Absolute or relative path to target movie property targetFrame -- frame number | marker name in target movie property jumpMode -- "Go to" | "Play and return" -- error checking: property myAlertMessage -- Identifies movie, sprite and behavior property mySaveAlertHook -- the jump() handler modifies the alertHook -- this property saves the initial value so -- that it can be reset after use -- EVENT HANDLERS -- on beginSprite me me.initialize() end beginSprite on mouseUp me me.jump() end prepareFrame -- PRIVATE METHODS -- on initialize(me) ---------------------------------------------------- -- Sent by beginSprite() -------------------------------------------------------------------- -- Convert targetFrame to an integer frame number if appropriate temp = value(targetFrame) if integerP(temp) then if string(temp) = targetFrame then targetFrame = temp end if end if if targetFrame = "" then targetFrame = 1 end if -- We can't test markers until we arrive in the target movie, so -- let's prepare an error message for an authortime alert, just in -- case. behaviorName = string (me) delete word 1 of behaviorName behaviorName = value(behaviorName) myAlertMessage = \ "BEHAVIOR ERROR: Movie: "&the moviePath&the movieName&RETURN&\ "Sprite: "&me.spriteNum&", Frame: "&the frame&", Behavior: "\ &behaviorName&RETURN&RETURN&\ "There is no marker ""E&targetFrame"E&" in this movie."&\ RETURN&"Please correct the parameters for the behavior above." end initialize on jump(me) ---------------------------------------------------------- -- Sent by mouseUp() -- -- * Jumps the playback head to the {target frame of the} target -- movie -- -- NOTE: "go|play {frame} of movie " can -- cause a "Frame not found" script error if an invalid marker name -- is used. To prevent an alert from appearing at run-time, the -- alertHook property is temporarily set to this instance. -------------------------------------------------------------------- mySaveAlertHook = the alertHook the alertHook = me if jumpMode = "Go to" then go targetFrame of movie targetMovie the alertHook = mySaveAlertHook else -- Play / play done play targetFrame of movie targetMovie -- The next line won't be executed until after "play done". If -- an error occurs with the previous line, the "on alertHook()" -- handler will already have restored the initial value. -- NOTE: until "play done" is executed, the alertHook will remain -- set to this instance. During this period, any errors other -- than "Frame not found" will be treated by the Director Player -- in its default manner: "Error: Stop/Continue?" if (the alertHook = me) then the alertHook = mySaveAlertHook end if end if end jump -- UTILITY HANDLERS -- on GetCurrentMovie(me, theScriptList, behaviorCount) ----------------- -- Reads the scriptList for the current sprite to determine if a -- movie has previously been selected: returns the current value of -- #targetMovie -------------------------------------------------------------------- -- theScriptList = sprite(the currentSpriteNum).scriptList -- behaviorCount = theScriptList.count thisScript = string(me) put "member("into thisScript.word[1] thisScript = value(thisScript) repeat while behaviorCount if theScriptList[behaviorCount][1] = thisScript then behaviorInitializers = value (theScriptList[behaviorCount][2]) if behaviorInitializers.findPos(#targetMovie) then return behaviorInitializers.getProp(#targetMovie) end if end if behaviorCount = behaviorCount - 1 end repeat -- The parameters for this behavior have not yet been set return "" end GetCurrentMovie on GetRelativePathTo(me, otherMovie) ---------------------------------- -- Calculates the relative path to the target movie, by comparing -- its full path name with that of the current movie. -------------------------------------------------------------------- thatMoviePath = otherMovie thisMoviePath = the moviePath saveDelimiter = the itemDelimiter pathDelimiter = the last char of the applicationPath the itemDelimiter = pathDelimiter repeat while TRUE thisFile = thisMoviePath.item[1] thatFile = thatMoviePath.item[1] if thisFile <> thatFile then exit repeat delete thisMoviePath.item[1] delete thatMoviePath.item[1] end repeat if thatMoviePath = otherMovie then relativePath = otherMovie else relativePath = "@" thisDeep = thisMoviePath.item.count repeat while thisDeep relativePath = relativePath&pathDelimiter thisDeep = thisDeep - 1 end repeat relativePath = relativePath&thatMoviePath end if the itemDelimiter = saveDelimiter return relativePath end GetRelativePathTo on getDefaultMovie(me) ------------------------------------------------ -- Called by getPropertyDescriptionList() -- -- * Returns "" (by default) or the relative path to the movie -- currently selected as targetMovie. If the user presses -- the Shift Key while opening the Behavior Parameters dialog, -- a FileIO "Open file" dialog will allow the user to choose -- a movie directly. -------------------------------------------------------------------- if the currentSpriteNum then theSprite = sprite(the currentSpriteNum) theScriptList = theSprite.scriptList behaviorCount = theScriptList.count if theScriptList.count() then -- Check if behavior has already been initialized currentMovie = me.getCurrentMovie(theScriptList, behaviorCount) else currentMovie = "" end if if the shiftDown and not xtrasMissing([#fileio]) then -- Choose a movie with FileIO Xtra or allow -- user to Cancel and maintain current choice fileIOInstance = xtra("fileIO").new() if the platform starts "Mac" then setFilterMask (fileIOInstance, "MV95MV97MV07MV08") else setFilterMask (fileIOInstance, "Director movies,*.d*r") end if chosenMovie = fileIOInstance.displayOpen() case (chosenMovie) of VOID, "": -- User cancelled if stringP(currentMovie) then chosenMovie = currentMovie else chosenMovie = "" end if otherwise -- A new movie was chosen: use a range list in the -- getPropertyDescriptionList() dialog so that the previous -- value is overridden. chosenMovie = [me.getRelativePathTo(chosenMovie)] end case else -- The author did not press Shift, or FileIO is absent chosenMovie = currentMovie end if else -- the currentSpriteNum is 0: return a dummy value chosenMovie = "" end if return chosenMovie end getDefaultMovie on xtrasMissing(xtrasList) ------------------------------------------- -- Called by getDefaultMovie() -- -- * Returns TRUE if any of the xtras in xtraList are missing. Once -- the handler has finished executing, xtrasList contains only the -- names of the missing xtras. -------------------------------------------------------------------- i = the number of xtras repeat while i xtrasList.deleteOne(xtra(i).name) i = i - 1 end repeat return xtrasList.count() end xtrasMissing -- ERROR CHECKING -- on alertHook(me, errorType, message) --------------------------------- -- Sent if an error occurs in jump() because the marker indicated by -- targetFrame does not exist in the target movie. -- -- * Displays an authortime-only alert explaining how the author -- can fix the problem. No alert will appear at runtime. If a -- Message window is available in a projector, the alert will be -- printed there. -------------------------------------------------------------------- -- Restore the previous value, even when the execution of the -- jump handler is blocked by a "play" command. the alertHook = mySaveAlertHook if message = "Frame not defined" then case the runMode of "Author": alert myAlertMessage "Projector": put myAlertMessage end case -- In Shockwave or a Projector, tell Director to continue if -- possible. In author mode, Director will always halt. return 1 else -- Some unexpected error occurred: let Director handle it return 0 end if end alertHook -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach(me, spriteType, spriteNumber) return spriteType = #graphic end isOKToAttach on getPropertyDescriptionList me propertiesList = [:] defaultMovie = me.getDefaultMovie() targetMovie = [ \ #comment: "On mouseUp, go to movie:"&RETURN&\ "(TIP: press Shift when opening this dialog to pick a movie).", \ #format: #string, \ #default: defaultMovie \ ] if listP(defaultMovie) then -- The user chose a movie via the FileIO dialog: replace the -- current value with the new default value by limiting the range -- of #targetMovie targetMovie[#range] = defaultMovie targetMovie[#default] = defaultMovie.getLast() end if propertiesList[ \ #targetMovie] = targetMovie propertiesList[ \ #targetFrame] = [ \ #comment: "Frame or marker in the other movie (optional):", \ #format: #string, \ #default: "" \ ] propertiesList[ \ #jumpMode] = [ \ #comment: "Jump Mode:", \ #format: #string, \ #range: ["Go to", "Play and Return"], \ #default: "Go to" \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip return \ "Use with graphic members."&RETURN&RETURN&\ "When the user clicks on a sprite with this behavior"&RETURN&\ "the playback head jumps to a chosen marker in a"&RETURN&\ "chosen movie."&RETURN&RETURN&\ "TIP: Press the Shift Key when you drop the behavior"&RETURN&\ "onto a sprite: a FileIO displayOpen dialog will let"&RETURN&\ "you locate a movie anywhere on your system, and save"&RETURN&\ "the relative path to the chosen movie." end getBehaviorTooltip on getBehaviorDescription return \ "GO MOVIE BUTTON"&RETURN&RETURN&\ "© July 2000, James Newton "&RETURN&RETURN&\ "A click on the sprite makes the playback head jump to any other "&\ "movie available to your system. An optional marker name can be "&\ "used to jump to a precise point in the new movie. (Use the "&\ "'Go Marker Button' behavior to jump to a marker in the current "&\ "movie)."&RETURN&RETURN&\ "TIP: Press the Shift Key when you drop this behavior onto a "&\ "sprite: a FileIO displayOpen dialog will let you locate a movie "&\ "anywhere on your system. This behavior will store the link as "&\ "relative path (or as an absolute path if the movie is located on "&\ "a different hard drive)."&RETURN&RETURN&\ "If you subsequently move either the current movie or the target "&\ "movie, a dialog will appear to allow you to relocate the target "&\ "movie. If this happens at authortime, it is best to reselect the "&\ "movie in the Behavior Parameters dialog so that the correct "&\ "relative path is stored."&RETURN&RETURN&\ "If you move both the current movie and the target movie together, "&\ "or if you move the folder that contains them both, no reselection "&\ "should be necessary... unless you initially entered a hard-coded "&\ "file path manually in the Behavior Parameters dialog"&RETURN&RETURN&\ "In order to make use of the Play and Return option, place a "&\ "Play Done command in the destination movie. If you do not do "&\ "this, your movie will use more memory than is necessary."&\ RETURN&RETURN&\ "PERMITTED MEMBER TYPES"&RETURN&"Graphic members"&RETURN&RETURN&\ "PARAMETERS:"&RETURN&\ " * Movie to jump to"&RETURN&\ " * Marker to jump to in the new movie (optional)"&RETURN&\ " * 'Go to' or 'Play and return'?"&RETURN&RETURN&\ "ASSOCIATED BEHAVIORS:"&RETURN&\ " + Go Marker Button"&RETURN&\ " + History Button"&RETURN&\ " + Resume Button"&RETURN&\ " + Mouse States (to alter rollover / mouseDown states)" end getBehaviorDescription