Grouping custom properties in a custompropertyset
Q: I have several custom properties I want to keep together. How can I do this?
Identify the properties you want to group together
For instance, a project may have several html files and related data:
project.html
menu.css
Colors.css
Colors.js
project.js
Animation.swf
Custom property sets
I think of custom property sets as arrays that are stored in the stack as custom properties. You could use normal array syntax for storing the properties. So where you might have
put "myProject" into myArray["projectName"]
put url("file:project.html") into myArray["html"]
put "Animation.swf" into myArray["swfFile"]
put url("binfile:Animation.swf") into myArray["binaryimage"]
put url("file:menu.css") into myArray["menucss"]
put url("file:Colors.css") into myArray["colorscss"]
put url("file:Colors.js") into myArray["colorsjs"]
put url("file:project.js") into myArray["projectjs"]
and where you would be storing the swf file as a custom property:
set the uBinaryImage of this card to compress(url("binfile:Animation.swf"))
you could say
set the uProject["projectName"] of this card to "myProject"
set the uProject["binaryimage"] of this card to compress(url("binfile:Animation.swf"))
set the uProject["swfFile"] of this card to "Animation.swf"
set the uProject["menucss"] of this card to url("file:menu.css")
set the uProject["colorscss"] of this card to url("file:Colors.css")
set the uProject["colorsjs"] of this card to url("file:Colors.js")
set the uProject["projectjs"] of this card to url("file:project.js")
This will create a new property set named "uProject" with the array-like entries stored as elements of the uProject set.
Retrieving properties from a custom property set
Getting the properties back from a custom property set is a bit more difficult. You can't just treat the set like an array:
put the uProject["filename"] of this card into myFilename
won't work.
You have to change the custompropertyset of the object you're working with (remember to set it back to empty when you're done).
set the custompropertyset of this card to "uProject"
-- at this point you can query the elements of the uProject set by issuing the command
-- put the customproperties of this card
put the swfFile of this card into tProjectFilename
put the projectjs of this card into tProjectJavaScript
set the custompropertyset of this card to empty
You can retrieve the custom property set back into an array:
set the custompropertyset of this card to "uProject"
put the customkeys of this card into tElements
repeat for each line tProp in tElements
put the tProp of this card into myArray[tProp]
end repeat
set the custompropertyset of this card to empty
now myArray contains the contents of the "uProject" custom property set:
put myArray["js"]
will give you the contents of the original "project.js" file.
Saving and retrieving the same way
You can also create more readable code by saving your custom property set elements in the same form as you retrieve them:
set the custompropertyset of this card to "uProject"
set the projectName of this card to "myProject"
set the binaryimage of this card to url("binfile:Animation.swf")
set the swfFile of this card to "Animation.swf"
set the menucss of this card to url("file:menu.css")
set the colorscss of this card to url("file:Colors.css")
set the colorsjs of this card to url("file:Colors.js")
set the projectjs of this card to url("file:project.js")
set the custompropertyset of this card to empty
or if the grouped data is already in an array:
put the keys of myArray into tKeys
set the custompropertyset of this card to "uProject"
repeat for each line tProp in tKeys
set the tProp of this card to myArray[tProp]
end repeat
set the custompropertyset of this card to empty
Using the Property Inspector
You can use the IDE's Property Inspector to view and manipulate custom property sets as well.
Select an object from the Project Browser and right- or control- click to bring up the contextual menu.
Select the Property Inspector and go to "Custom".
Select a custom property set
The custom properties displayed by default are from a custompropertyset named "customKeys". You can select a different set from the drop down menu of the Property Editor. The screenshot is showing a property set belonging to the IDE. The custom set selected (1) is cRevTable. The properties in this set are shown and can be selected in the field below it (2). The current property selected is shown in the "Key" field (3), and the value of the property is shown below (4).
Notes
You can't go more than one level deep in custom property sets.
So as tempting as it may seem, you can't say
set the uEmployees[employeeID]["firstname"] of this stack to "Fred"
or
set the custompropertyset of this stack to "uEmployees"
set the employeeID["firstname"] of this stack to "Fred"
set the custompropertyset of this stack to empty
0 Comments
Add your comment