-- MovieScript "FunctionLib" -- @version 1.2.4 -- @History -- 1.2.4 - Added Equal() -- 1.2.3 - Added some functions for getting info about current Xtras -- 1.2.1 - Added the GetScriptName function. Fixed bug in the cc function if used with -- the Debugger script -- 1.2 - Fixed a bug where this script was referring to its old name (Xlibfunctions) -- - Cached the Xtra list for checking for the existences of an Xtra -- - Added the memberType function -- -- 1.1 Changed the scriptP function to work with DMX2004 --- STATIC SCRIPT PROPERTIES -------------------------------------- property __AllMovieGlobalHandlerNames property __AllXtraGlobalHandlerNames property __XtraGlobalMethodNames property __XtraInstanceMethodNames property __XtraStaticMethodNames property __XtraList property __XtraFileList --- GLOBAL FUNCTION ----------------------------------------------- on equal (a, b) -- check the ilk, and then wrap in lists -- for case-sensitivity of strings if a.ilk = b.ilk then return ([a] = [b]) else return 0 end on die str alert(str) halt end on cc (msg, from) -- use instead of 'put' if scriptP("Debugger") then script("debugger").Note(Msg, from) else if the runMode = "Author" then put from && msg end on hang (ms) -- freeze the movie (for a max of two seconds) ms = max(1, min(ms, 2000)) repeat while the milliseconds < ms end repeat end on memberType(memberRef) -- return the member type or #empty if (memberRef.ilk = #member) then return memberRef.type else return #empty end on xtraP (xtraName) -- Test for the existence of a named Xtra. Returns 1 if the Xtra found return script("FunctionLib").__XtraP(XtraName) end on scriptP( aScriptName ) -- test whether the specified script exists if member(aScriptName).ilk = #member then return (member(aScriptName).type = #Script) end if return false end on handlerP (FunctionNameAsSymbol, objectRef) -- Test for the existence of a named function/handler. Can specify the scope -- (window, xtra, instance, script, sprite or list of any of these) to test. -- The default scope is (the activeWindow). -- -- -- Examples uses: -- if handlerP(#Foo) then foo() -- if handlerP(#Foo, someMIAW) then tell someMIAW to foo() -- if handlerP(#Foo, myInstance) then myInstance.foo() -- if handlerP(#Foo, sprite(1)) then sprite(1).foo() if FunctionNameAsSymbol.ilk <> #Symbol then return 0 if voidP(objectRef) then objectRef= (the activeWindow) return script("FunctionLib").___handlerP(FunctionNameAsSymbol, objectRef, []) end on GetScript ( obj) -- returns the script object used to create the object -- or an empty string if now script found if obj.ilk = #script then return obj else if obj.ilk <> #instance then return "" s = string(obj) the itemDelimiter = QUOTE return script(s.item[2..(s.item.count-1)]) end on GetScriptName( obj) -- returns the name of script used to create the object -- or an empty string if now script found i = obj.ilk case(i) of #instance, #script: s = string(obj) the itemDelimiter = QUOTE return s.item[2..(s.item.count-1)] otherwise return "" end case end on GetXtraInfo (XtraName) -- returns the Xtra's entry in player.Xtralist. -- Note: Searches the Xtra list using a simple name 'starts' -- eg: put GetXtraInfo("Flash") -- [#fileName: "Flash Asset PPC", #version: "10.1.1"] xlist = script("FunctionLib").__GetXtraFileList() repeat with x in xlist if x.fileName starts XtraName then return x end if end repeat end on CheckXtraVersion (XtraName, minVersion) -- Checks the specified Xtra meets the required minimun version. -- The minVersion can either be a string (eg. "10.1.1") or a list -- (eg [10,1,1]). -- Returns 1 if the Xtra is found and meets the min version requirements. -- Returns 0 if the Xtra is found but not meeting requirements. -- Returns -1 if the Xtra is not found or the min requirments not found. -- Example Use: -- if (CheckXtraVersion("Flash", "10.1.1") < 1 ) die("Flash Xtra is missing or too old") v = GetXtraInfo(XtraName)[#version] if voidP(v) then return -1 vList = VersionStrToVersionList(v) if minVersion.ilk = #String then minVersion = VersionStrToVersionList(minVersion) else if minVersion.ilk <> #list then return -1 repeat with i =1 to 3 if vList[i] < minVersion[i] then return 0 end repeat return 1 end on VersionStrToVersionList(v) -- Convert a version string (eg. "10.1.3") in to a list that -- is at least 3 elements long vlist = [0,0,0] the itemDelimiter = "." mx = v.item.count repeat with i = 1 to mx vv = value(v.item[i]) if voidP(vv) then vList[i] = v else vList[i] = vv end repeat return vList end --- PRIVATE METHODS ----------------------------------------------- on __XtraP(this, XtraName) if voidP(this[#__XtraList]) then l = [] nx = the number of Xtras repeat with j = 1 to nx n = symbol(Xtra(j).name) l.append( n ) end repeat this.__XtraList = l end if return (this.__XtraList.getOne(symbol(XtraName)) <> 0) end on __GetXtraFileList(this) if voidP(this[#__XtraFileList]) then this.__XtraFileList = [] nx = count(_player.xtraList) repeat with j = 1 to nx thisXtra = _player.xtraList[j] this.__XtraFileList.append( thisXtra ) end repeat end if return (this.__XtraFileList) end on ___handlerP (this, FunctionNameAsSymbol, objectRef, checkedList) if checkedList.getOne(objectRef) then return 0 -- protect against circular refs else checkedList.add(objectRef) case (objectRef.ilk) of #window: -- check moviescripts for the handler foundHandlers = this.___GetAllMovieHandlers(objectRef) if (foundHandlers.getOne(FunctionNameAsSymbol) <> 0) then return TRUE -- if not found, check for global functions provided by xtras foundHandlers = this.___GetAllXtraGlobalHandlers() return (foundHandlers.getOne(FunctionNameAsSymbol) <> 0) #xtra: foundHandlers = this.___GetXtraStaticMethods(objectRef) return (foundHandlers.getOne(FunctionNameAsSymbol) <> 0) #instance: ObjectRefAsStr = string(objectRef) if ObjectRefAsStr starts " 0) else if ObjectRefAsStr starts " 1 if "* " contains thisLine.char[1] then delete thisLine.char[1] else exit repeat end repeat handlerName = thisLine.word[1] aList.add(handlerName) end if end repeat Cached.setAProp(XtraID, aList) end if return aList end on ___GetAllXtraInstanceHandlers (this, XtraInstace) -- Returns a list of methods that work with Xtra instances -- (ie not global functions provided by the Xtra) if voidP(this.getAProp(#__XtraInstanceMethodNames))then this.setAProp(#__XtraInstanceMethodNames, [:]) end if Cached = this.getAProp(#__XtraInstanceMethodNames) xstr = string(XtraInstace) xstr = xstr.char[(offset(QUOTE, xstr)+1)..xstr.length] XtraName = xstr.char[1..(offset(QUOTE, xstr)-1)] aList = Cached.GetAProp(XtraName) if voidP(aList) then aList = [] if xtraP(XtraName) then XtraRef = xtra(XtraName) iStr = XtraRef.interface() mx = iStr.line.count if iStr.line[1] starts "xtra " then firstLine = 2 else firstLine = 1 repeat with i = firstLine to mx thisLine = iStr.line[i] if thisLine starts "--" then next repeat if thisLine starts "*" then next repeat if thisLine starts "+" then repeat while thisLine.length > 1 if "+ " contains thisLine.char[1] then delete thisLine.char[1] else exit repeat end repeat handlerName = thisLine.word[1] aList.add(handlerName) else aList.add(thisLine.word[1]) end if end repeat Cached.setAProp(XtraName, aList) end if end if return aList end on ___GetXtraStaticMethods (this, XtraRef) -- Returns a list of static methods of the specified Xtra -- (ie they are listed in the interface as "+ methodname") if voidP(this.getAProp(#__XtraStaticMethodNames))then this.setAProp(#__XtraStaticMethodNames, [:]) end if Cached = this.getAProp(#__XtraStaticMethodNames) XtraID = XtraRef.name aList = Cached.GetAProp(XtraID) if voidP(aList) then aList = [] iStr = XtraRef.interface() mx = iStr.line.count repeat with i = 1 to mx thisLine = iStr.line[i] if thisLine starts "+" then repeat while thisLine.length > 1 if "+ " contains thisLine.char[1] then delete thisLine.char[1] else exit repeat end repeat handlerName = thisLine.word[1] aList.add(handlerName) end if end repeat Cached.setAProp(XtraID, aList) end if return aList end