In response to a question on the macromedia.director.lingo newsgroup:
"How can I sort a list of names from a list of property lists, display
the sorted names in a text member, click a name and display all the related
properties in a text member on another frame?"
Click a name to see the information related to that name.
In this example, the names were sorted in the beginSprite handler of the
behavior on the text sprite.
|
The Lingo:
(Syntax highlighting provided by David Mennenoh's way cool HTML-ingo utility).
-- Movie script --
global lDbase -- the main database list
global lNames -- stores the names in their original order
on prepareMovie
initDbase
end
on initDbase
lDbase = [[#company:"Advanced Ind.",#name:"Judy"],¬
[#company:"Image Co.",#name:"pauline"],¬
[#company:"Multilink Enterprise",#name:"kent"]]
end
on sortEm
namesTxt = ""
lNames = []
theCount = lDbase.count
repeat with i = 1 to theCount
theName = lDbase[i].name
lNames.add(theName)
end repeat
lTemp = duplicate(lNames) -- so we don't modify lNames
sort lTemp
theCount = lTemp.count
repeat with i = 1 to theCount
theName = lTemp[i]
namesTxt = namesTxt &theName &RETURN
end repeat
numLines = namesTxt.line.count
delete line numLines of namesTxt
member("names").text = namesTxt --#text member
end
on displayEm theName -- passed by the clicked sprite
thePos = lNames.getOne(theName)
theCompany = lDbase[thePos].company
outString = "Company:" &&theCompany &&" Name:" &&theName
member("output").text = outString
end
|
-- behavior on text sprite --
property spriteNum, mySprite
property myMem
on beginSprite me
mySprite = sprite(spriteNum)
myMem = mySprite.member
sortEm
end
on mouseUp me
theWord = pointToWord(mySprite, the mouseLoc)
theName = myMem.text.word[theWord]
displayEm theName
go to "display"
end
|