I just spent a few hours writing a little utility some of you might find
handy. The code follows--it's pretty specific, but easy enough to
modify.
I inherited a project that had literally thousands of hard-coded
behaviors attached to sprites, and they all do basically the same
thing--they set a global and go to a glossary movie. The only
difference, really, is the value of the global.
That sort of code is near impossible to work with, so I needed to
replace it with my own paremeterized behavior. Now, without further ado,
the utility scripts to do this (these are movie scripts):
-- Find new glossary behaviors in the internal scripts cast
-- and add them to the NewGlossList field member. These will be
-- incorporated into the list of all glossary behaviors
on findNewGlossBehaviors whichCast
-- grab the list of bahaviors we already have
lExistingBehaviors = value(field("glossaryList"))
repeat with i = 1 to the number of members of castLib whichCast
if (member i of castLib whichCast).type = #script then
-- get the text and see if it has the variable theGlossWord
myText = (member i of castLib whichCast).scriptText
gwOffset = offset("theGlossWord", myText)
if gwOffset > 0 then -- this one is a glossary behavior
behaviorName = (member i of castLib whichCast).name
-- check to see if we already have this behavior in the list
if (voidP(lExistingBehaviors.getaProp(behaviorName))) then
-- extract the hard-coded value of theGlossWord and add it to
the new behaviors field
codeEnd = myText.length
codeStart = gwOffset + 12
myText = myText.char[codeStart..codeEnd]
startGlossWord = offset("theGlossWord", myText)
glossText = myText.char[startGlossWord + 14..mytext.length]
startGlossWord = offset(Quote, glossText)
glossText = glossText.char[(startGlossWord +
1)..glossText.length]
endGlossWord = offset(Quote, glossText) - 1
theGlossWord = glossText.char[1..endGlossWord]
put QUOTE & behaviorName & QUOTE & ": " & QUOTE & theGlossWord
& QUOTE & ", "\
after field ("NewGlossList")
end if
end if
end if
end repeat
end
-- replace all the glossary behaviors in the list with
-- the glossShow behavior
on updateGlossaries
lGlossScripts = value(field("glossaryList"))
glossListCount = lGlossScripts.count
glossScriptMem = member 27 of castlib 3
repeat with i = 1 to the lastFrame
go to frame i
repeat with j = 1 to 500
if sprite(j).scriptlist.count > 0 then
repeat with k = 1 to glossListCount
behaviorName=lGlossScripts.getPropAt(k)
if offset(behaviorName ,sprite(j).scriptlist[1][1].name) > 0
then
glWord = lGlossScripts.getAt(k)
sprite(j).setScriptList([[glossScriptMem, "[#pGlossWord: " &
QUOTE & glWord & QUOTE & "]"]])
put "frame: " & i && "sprite: " & j
end if
end repeat
end if
end repeat
updateFrame
end repeat
end
-- replace a single named glossary behavior with the
-- glossShow behavior
on updateAGloss behaviorName, glWord
glossScriptMem = member 27 of castlib 3
repeat with i = 1 to the lastFrame
go to frame i
repeat with j = 1 to 500
if sprite(j).scriptlist.count > 0 then
if offset(behaviorName ,sprite(j).scriptlist[1][1].name) > 0
then
sprite(j).setScriptList([[glossScriptMem, "[#pGlossWord: " &
QUOTE & glWord & QUOTE & "]"]])
put "frame: " & i && "sprite: " & j
-- if not voidP(sprite(i).scriptlist[1][2]) then
-- put sprite(i).scriptlist[1][2]
-- end if
end if
end if
end repeat
updateFrame
end repeat
end
-- step through all the sprites to check for possible
-- missed glossary behaviors
on checkGloss
glossScriptMem = member 27 of castlib 3
repeat with i = 1 to the lastFrame
go to frame i
repeat with j = 1 to 500
if sprite(j).scriptlist.count > 0 then
theScript = sprite(j).scriptlist[1][1]
if offset("GlossShow" ,sprite(j).scriptlist[1][1].name) > 0 then
-- put sprite(j).scriptlist[1][2]
if (offset("gloss" ,sprite(j).scriptlist[1][2]) > 5) \
OR (sprite(j).scriptlist[1][2].length < 22) then
put "frame: " & i && "sprite: " & j &&
sprite(j).scriptlist[1][2]
end if
end if
end if
end repeat
updateFrame
end repeat
end
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/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!]