|
findIlk
Here's a piece of utility code that may or may not help.
It was designed to diagnose a different symptom: sometimes when
you "forget" a window, it remains obstinately on-screen. This
occurs if you have a pointer to the window hidden in a property
in some obscure object. The pointer will maintains the window
in existence until it is set to a different value.
The code below seeks out any given #ilk: try findIlk(#window).
Cheers,
James
--------------------------------------------------------------------
on findIlk(whichIlk, hostObject, thisPath, listOfPaths, doneList) ----
-- * Performs a tree-walk of all global lists and objects and
-- returns the list of all items whose ilk is <whichIlk>.
--
-- If <hostObject> is defined then the search is limited to that
-- object and its sub-objects.
--
-- There is no need to use the parameters <thisPath>, <listOfPaths>
-- or <doneList> in your call: these are used internally by the
-- handler when it calls itself recursively.
--
-- Example: put findIlk(#window)
-- -- ["(the globals).gMIAW", "(the windowList)[1]"]
--------------------------------------------------------------------
if ilk(listOfPaths) <> #list then
listOfPaths = []
end if
if ilk(doneList) <> #list then
doneList = []
end if
if objectP(hostObject) then
objectName = string(hostObject)
if objectName starts "<Xtra child " then
-- Ignore xtras since xtraInstance.count() does not function
else
hostIlk = ilk(hostObject)
doneList.append(hostObject)
i = hostObject.count()
repeat while i
if hostIlk = #list then
element = hostObject[i]
else
theProp = hostObject.getPropAt(i)
element = hostObject.getAProp(theProp) --One possible syntax
end if
if hostIlk = #list then
path = thisPath &"["&i&"]"
else
path = thisPath &"."&theProp
end if
case ilk(element) of
whichIlk: listOfPaths.append(path)
#list, #propList, #instance:
if not doneList.getPos(element) then
findIlk(whichIlk, element, path, listOfPaths, doneList)
else
nothing
end if
end case
i = i - 1
end repeat
end if
else
-- Look in all the places where an item with the expected ilk
-- might be stored
thisPath = "(the globals)"
findIlk(whichIlk, the globals, thisPath, listOfPaths, doneList)
thisPath = "(the windowList)"
findIlk(whichIlk, the windowList, thisPath, listOfPaths, doneList)
thisPath = "(the actorList)"
findIlk(whichIlk, the actorList, thisPath, listOfPaths, doneList)
spriteNumber = the lastChannel
repeat while spriteNumber
instanceList = sprite(spriteNumber).scriptInstanceList
thisPath = "(sprite "&spriteNumber&").scriptInstanceList"
findIlk(whichIlk, instanceList, thisPath, listOfPaths, doneList)
spriteNumber = spriteNumber - 1
end repeat
windowNumber = (the windowList).count()
repeat with i = 1 to windowNumber
theWindow = window i
if ilk (theWindow) <> #window then
next repeat
end if
windowName = QUOTE&theWindow.name"E
tell theWindow
thisPath = "<window "&windowName&">(the actorList)"
findIlk(whichIlk,the actorList,thisPath,listOfPaths,doneList)
spriteNumber = the lastChannel
repeat while spriteNumber
instanceList = sprite(spriteNumber).scriptInstanceList
thisPath = " ¬
<window "&i&">(sprite "&spriteNumber&").scriptInstanceList"
findIlk(whichIlk,instanceList,thisPath,listOfPaths,doneList)
spriteNumber = spriteNumber - 1
end repeat
end tell
windowNumber = windowNumber - 1
end repeat
end if
return listOfPaths
end findIlk
|