
If tResult is not empty then answer error "Failed to read preferences file at location: " & tPreferencesFile Put url ( "file:" & tPreferencesFile) into tPreferencesData # Always check for the result when reading files # as its possible that the file may have been deleted or moved. Set the itemDelimiter to comma # Read the preferences data from the file into a variable. Put item 1 to -2 of the effective filename of this stack & "/Preferences.xml" into tPreferencesFile set the itemDelimiter to slash local tPreferencesFile # This is not essential but its good practice to avoid tricky bugs # that can arise due to unexpected delimiter values. # Note that we restore the itemDelimiter to comma (its default value) afterwards. # This is for now assumed to be in the same location as the stack / application. private function readPreferencesToXMLTree This tree allows us to manipulate the XML data easily.Īdd the code to read the XML file as below. This is done in two steps, first the file is read into a variable like any other text file would be, secondly, an XML "tree" is created from the file. Next, we implement a function to read the XML. Note that this code doesn't do anything just yet, because we haven't yet implemented the function readPreferencesToXMLTree and the command processPreferencesTree. # This will free up the memory that the tree was using and prevent our application # using more memory than it needs or "leaking" memory by creating multiple trees # without closing any of them. If tTree is empty then exit loadPreferencesĮnd if # Read the preferences we require from the tree and display them. Put readPreferencesToXMLTree() into tTree The tree is represented as a number, the actual tree structure and data is managed by LiveCode and so we don't need to worry about it.

This function reads the XML file, and returns the tree.

The second part is to process the tree and extract the data from it.

The first part is reading the file into memory and creating an XML "tree". There are two parts to loading the preferences file. When the button is clicked, load up the preferences and put them into the field on mouseUp For this example we are going to load an XML file that contains preferences for our application.īegin the script with the following code:ġ. Edit the script of the button by selecting it, then clicking on the "Script" button in the main menu bar.
