Date: Tue, 8 Aug 1995 19:20:13 -0500 From: Charles Wiltgen <cwiltgen@FANCYMEDIA.COM> Subject: Some scriptsHere's some general utility scripts, plus a trackButton script that works like a standard button (although I still want to write a version that doesn't halt animations, etc.)
Have fun, and let me know if you improve them.
-- General cast-swapping/animation utility -- Usage: swapSprite( theButtonChannel, theButtonHiliteSprite ) on swapSprite whichChannel, whichSprite set the castNum of sprite whichChannel to whichSprite updateStage end swapSprite
-- This handler tracks mouse clicks like "normal" buttons
-- Usage: if trackButton( theButtonChannel, theButtonSprite, ...
-- the mouseCast ) then doWhatever
-- Note: This handler depends on a "mouseWithin" cast in
-- ( whichCast + 1 ) and a hilite cast in ( whichCast + 2 ).
on trackButton whichChannel, whichSprite, whichCast
global kMinHiliteTime
-- change to "hilite" state
swapSprite( whichChannel, ( whichSprite + 2 ) )
updateStage
puppetSound "Mouse down"
-- wait the minimum amount
startTimer
repeat while the timer < kMinHiliteTime
end repeat
-- wait until mouseUp
repeat while the stillDown
if ( the mouseCast <> whichCast ) and ...
( the mouseCast <> whichCast + 2 ) then
-- mouse is not over button
swapSprite( whichChannel, whichSprite )
updateStage
else
swapSprite( whichChannel, ( whichSprite + 2 ) )
updateStage
end if
end repeat
-- is this needed?
repeat while soundBusy(1)
end repeat
puppetSound "Mouse up"
put the mouseCast into theMouseUpCast
-- change to "normal" state
swapSprite( whichChannel, whichSprite )
-- if the mouseUp happened on the button
-- (in normal or hilite states) then do it
if ( theMouseUpCast = whichCast ) or ...
( theMouseUpCast = whichCast + 2 ) then return TRUE
else return FALSE
end trackButton
on waitSeconds howManySeconds set howLong = ( howManySeconds * 60 ) startTimer repeat while the timer < howLong end repeat end waitSeconds
on waitTicks howMany startTimer repeat while the timer < howMany end repeat end waitTicks
-- This function returns the suffix (separated by your delimiter
-- of choice) of a string.
-- Usage: stripSuffix( "filename.txt", "." )
on stripSuffix theString, theDelimiter
set theLength = the number of chars in theString
set whichChar = 1
repeat while ( char whichChar of theString <> theDelimiter ) and ...
( whichChar <= theLength )
set whichChar = whichChar + 1
end repeat
if ( whichChar <> 1 ) and ( whichChar <= theLength ) then
-- we found the delimiter
put char 1 to ( whichChar - 1 ) of theString into theNewString
else
set theNewString = empty
end if
return theNewString
end stripStuffix
on showCursor cursor -1 -- arrow end showCursor on showWaitCursor cursor 4 -- wait end showWaitCursor on hideCursor cursor 200 -- blank cursor end hideCursor
-- This handler is an easier-to-remember (for me, anyway) version of
-- puppetSound that checks for the existance of name-referenced sounds
-- and does an updateStage (to play it) automatically.
-- Usage: playSound( "Doh!" ) / playSound( "Doh!", 2 ) / playSound( 69, 2 )
on playSound whichSound, whichChannel
if integerP( whichSound ) then
puppetSound whichChannel, whichSound
else
set whichCast = the number of cast whichSound
if ( whichCast = -1 ) then alert "Can't find sound" && quote & ...
whichSound & quote & "!" -- safety
puppetSound whichChannel, the number of cast whichSound
end if
updateStage -- to get it to play
end playSound
-- Usage: if not computerCanPlayAudio( ) then alert ...
-- "What?! Buy a sound card, for chrissakes!"
on computerCanPlayAudio
if the machineType < 256 then -- Mac
return TRUE
else -- Windows
mci "capability waveaudio can play"
if the result = "true" then
return TRUE
else
return FALSE
end if
end if -- the machineType
end computerCanPlayAudio
-- This function returns TRUE if the file exists, and FALSE if it doesn't.
-- Usage: if checkForFile( "Doh!" ) then doWhatever
on checkForFile relativePath
set checkFileObj = FileIO( mNew, "read", ...
( the pathName & relativePath ) )
if not objectP( checkFileObj ) then
alert "File is missing!"
return FALSE
else
return TRUE
end if
checkFileObj( mDispose )
end checkForFile
-- This function returns TRUE if the file exists,
-- and FALSE if it doesn't.
-- Usage: if checkForAbsoluteFile("Hard Drive:Simpsons:Intro.mov") ...
-- then doWhatever
on checkForAbsoluteFile absolutePath
set checkFileObj = FileIO( mNew, "read", absolutePath )
if not objectP( checkFileObj ) then
alert "File is missing!"
return FALSE
else
return TRUE
end if
checkFileObj( mDispose )
end checkForAbsoluteFile
-- This should be called for any "go to"s if your palette is under -- Lingo control. (You shouldn't have to, but Director has a bug.) on refreshPalette puppetPalette the framePalette end refreshPalette
-- Mac/PC QuickTime present indicator
-- Usage: if not QuickTimeIsInstalled( ) then alert ...
-- "You need QuickTime to use this movie!"
on QuickTimeIsInstalled
if the machineType < 256 then -- Mac
if the quickTimePresent then
return TRUE
else
return FALSE
end if
else -- Windows
mci "capability QTWVideo can play"
if the result = "true" then
return TRUE
else
return FALSE
end if
end if -- the machineType
end QuickTimeIsInstalled
-- PC-only (for now) QuickTime version getter
-- Usage: if not QuickTimeVersionIsCurrent( ) then alert ...
-- "You need to upgrade QuickTime!"
on QuickTimeVersionIsCurrent
mci "info QTWVideo version"
if value( the result ) < 2.351 then
return FALSE
else
return TRUE
end if
end QuickTimeVersionIsCurrent