-- @Version: 1.0.0 -- @Author Luke Wigley -- @Source: http://www.lingoworkshop.com/Codelib/xlib.php -- @Description -- Function to list cast members that do not appear to be used either in the -- score, or referenced in scripts. -- @Notes -- Notes - all scripts are assumed to be used. Lingo expressions are not evaluated. -- @Requires xtra "PregEx" from OpenXtras.org on FindUnusedCastMembers( ) if member("FlightChecker.CastCleaner.ls").type <> #script then alert ("Please name the script containing the 'FindUnusedCastMembers' function 'FlightChecker.CastCleaner.ls')") halt end if this = script("FlightChecker.CastCleaner.ls") put "Generating list of members used in the score:" MemberInScore = this.__GetNonScoreBasedMembers() put "Found " & count(MemberInScore) & " members in the score" put "Generating list of members referenced in scripts" MembersReferencedInScripts = this.__GetScriptReferencedMembers() put "Found " & count(MembersReferencedInScripts) & " members referenced in scripts" Suspects = [] Put "Members that do not appear to be used:" repeat with c = 1 to the number of castlibs repeat with n = 1 to the number of members of castlib c m = member(n,c) if m.type <> #script AND m.type <> #empty then if NOT (MemberInScore.getOne(m)) then if NOT (MembersReferencedInScripts.getOne(m)) then put m && "[""E&m.name"E && m.type &"]" end if end if end if end repeat end repeat end on __GetNonScoreBasedMembers (this) -- might be a clever way of doing this with -- dispatchCommand or something. THis way trolls -- through the score - a bit slow. usedMembers = [] here = the frame _movie.updateLock = 1 repeat with f = 1 to the lastframe go to frame f repeat with c = 1 to the lastChannel m = sprite(c).member if (m.type <> #empty) then if not(usedMembers.getOne(m)) then usedMembers.append(m) end if end repeat -- now check the 'special channels' with some -- extra kooky lingo if the frameScript > 0 then m = member(the frameScript) if not(usedMembers.getOne(m)) then usedMembers.append(m) end if if the framePalette > 0 then m = member(the framePalette) if not(usedMembers.getOne(m)) then usedMembers.append(m) end if if the frameSound1 > 0 then m = member(the frameSound1) if not(usedMembers.getOne(m)) then usedMembers.append(m) end if if the frameSound2 > 0 then m = member(the frameSound2) if not(usedMembers.getOne(m)) then usedMembers.append(m) end if if the frameTransition > 0 then m = member(the frameTransition) if not(usedMembers.getOne(m)) then usedMembers.append(m) end if end repeat go to here _movie.updateLock = 0 return usedMembers end on __GetScriptReferencedMembers (this) rList = [] repeat with c = 1 to the number of castlibs repeat with n = 1 to the number of members of castlib c m = member(n,c) case( m.type) of #script : s = m.scripttext this.__AddScriptReferencedMembers(s, rList) #text : this.__AddFontMembers(m, rList) end case end repeat end repeat return rList end on __AddScriptReferencedMembers (this, scriptToSearch, rList) -- Find named members if (PRegEx_SearchBegin([scriptToSearch], "member\b(?:[ \(]*?)""E&"([^\r\n]+?)""E, "gi") > 0) then repeat while (PRegEx_SearchContinue() > 0) whatMember = PRegEx_GetMatchString(1) if stringP(whatMember) then if not(rList.getOne(member(whatMember))) then rList.append(member(whatMember)) --put "found reference to " & whatMember end if end repeat end if if (PRegEx_SearchBegin([scriptToSearch], "field\b(?:[ \(]*?)""E&"([^\r\n]+?)""E, "gi") > 0) then repeat while (PRegEx_SearchContinue() > 0) whatMember = PRegEx_GetMatchString(1) if stringP(whatMember) then if not(rList.getOne(member(whatMember))) then rList.append(member(whatMember)) end if end repeat end if if (PRegEx_SearchBegin([scriptToSearch], "script\b(?:[ \(]*?)""E&"([^\r\n]+?)""E, "gi") > 0) then repeat while (PRegEx_SearchContinue() > 0) whatMember = PRegEx_GetMatchString(1) if stringP(whatMember) then if not(rList.getOne(member(whatMember))) then rList.append(member(whatMember)) end if end repeat end if -- Find numbered members? (anyone do this?) if (PRegEx_SearchBegin([scriptToSearch], "member\b(?:[ \(]*?)(\d+(,\s*\d+)?)", "gi") > 0) then repeat while (PRegEx_SearchContinue() > 0) whatMember = PRegEx_GetMatchString(1) if stringP(whatMember) then if not(rList.getOne(member(whatMember))) then rList.append(member(whatMember)) --put "found reference to " & whatMember end if end repeat end if end on __AddFontMembers (this, m, rList) fn = m.font fm = member(fn) if not voidP(fm) then if (fm.type = #font) then -- check this if NOT (rList.getOne(fm)) then rList.append(fm) end if end if end