Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.


B7003 - How do I convert a property list to a linear list?

by - Joseph Ganci

Does anyone have a way to covert a property list to a linear list without using repeat loops and Character functions? For example, how do you convert:

[[ #value1:"abc", #value2:"123", #type:501] [#status:"displayed", #URL:"./images", #type:32 ]]

into -->

[ ["abc", "123", 501] ["displayed", "./images", 32] ]

I can use repeat loops to strip all the characters between '#' and ':' off and it works but I just thought there might be a better way.

BTW: if your wondering why I want to do this? This list must be written to a text file and then used by another program.

Well, I can't think of a way to do it without Repeat loops, but I have found a way to avoid all that nasty Character stuff. In fact, the following script will work without any of that:

proplist := [[ #value1:"abc", #value2:"123", #type:501], [#status:"displayed", #URL:"./images", #type:32 ]]

count := ListCount(proplist)
thelist := Array([], count)
repeat with i := 1 to count
   repeat with j := 1 to ListCount(proplist[i])
     thelist[i][j] := proplist[i][PropertyAtIndex(proplist[i], j)]
   end repeat
end repeat

The first line just sets up a sample property list (yours). The rest you can pretty much use as is for any size list. Hope this helps!


I think I understand this code, but I'm a little confused about the syntax. What is the difference between



thelist[i,j]? Similarly, you have written

PropertyAtIndex(proplist[i],j) where I would have tried


Is the syntax for nested property lists different from that for a regular multi-dimensional lists? Of course, what you have here is a linear list of property lists. Whatever, I am confused.

There is no difference between




It's a matter of personal preference. Someone yesterday reported to me that they have experienced problems in the past with using the [i][j] approach, but I've never had a problem with it, and use lists in everything I do. However, since the person who reported it to me is someone I respect as an Authorware expert, keep it in mind if you ever see a problem that goes away after you switch it to [i, j]. I prefer the [i][j] approach because it's more visual for me. It clearly sets apart each subscript whereas commas are also used to separate arguments in functions and even divisions of numbers when shown on the screen.

As for why I wrote this line this way:

thelist[i][j] := proplist[i][PropertyAtIndex(proplist[i], j)]

I couldn't write it the way you suggested:

thelist[i][j] := proplist[i][PropertyAtIndex(proplist[i, j])]

because it simply wouldn't work. The PropertyAtIndex function expects two arguments, the property list and the index. If we changed it to your approach, there would only be one argument: proplist[i, j]. The way I wrote it, there are two: proplist[i] (the property list) and j (the index).

I hope this helps!

There are 0 reviews
Add your review