How can a Director movie write (save) text to disk and read it back again?
Director provides several ways to read and write text data from a local drive.
SetPref and getPref
The Lingo commands setPref and getPref enable Director movies to write text to a default folder location and read text from that location with some limitations.
Using setPref in a projector(Director 6.02 and above)
SetPref enables text to be written from a projector to a text file in a default location. When the setPref command is executed from a projector a folder named "Prefs" is created in the same folder that contains the projector. A text file is also created in the "Prefs" folder.setPref does not allow a path to be specified when writing a file, it will only save the file to the"Prefs" folder. For this reason, this command is not suitable for use in projectors running on non-writable media, such as a CD-ROM or a locked floppy disk. If setPref attempts to execute from a projector residing on non-writable media, a "Disk locked" or other message will be generated and no file will be written.
Using getPref in a projector (Director 6.02 and above)
GetPref enables a projector to read text from a file in the default folder named "Prefs". GetPref can read from a text file in this folder, even if it is on locked media. The "Prefs" folder does not have to be created using the setPref command in order to function with getPref, it may be manually created and inserted to the default location.
Using setPref and getPref in Shockwave (Director 5.0.1 and above)
SetPref and getPref enable text to be written to and read from the users local disk. When the setPref command is executed a default folder named "Prefs" is created in the Shockwave system folder on the local disk (see note about this folder below) and the specified text is written to a newly created text file in that folder. For security reasons, text can only be written to and read from this folder; read and write access to other folders is not allowed. For information about the location of the Shockwave system folder on various platforms see Xtras downloading overview (TechNote 12204). For more information about other features that are not considered "Shockwave Safe" see Shockwave Security (TechNote 3199).
Using setPref is the only way that Shockwave can write to a local disk. In a browser, data written by setPref is not private; any Shockwave movie can read this information. Do not store confidential information using SetPref.
See How do I use Get and SetPref? (TechNote 15199)and the accompanying sample movie for more information on using those commands.
Note:The text file created by SetPref is a standard text file, and GetPref can only read from a standard text file.
Using the FileIO Xtra projectors (Director 5.0.1 and above)
The FileIO Xtra offers a tremendous amount of flexibility for writing files to a disk and reading files from a disk. The FileIO Xtra can be used in projectors, but not in Shockwave movies. It is not considered a Shockwave Safe Xtra. For more information about Shockwave Security, see Shockwave Security (TechNote 3199)
For more information on the FileIO Xtra, refer to the following:
How to use the FileIO Xtra (TechNote 14607) contains an example of how to use the FileIO Xtra, including the Director authoring file available for download.
FileIO Xtra examples (TechNote 3192) has example FileIO scripts.
Director 7.02 - 8.5 users can open the sample movie in the Director application folder called read_write_text.dir, which is an example of using both FileIO and setPref and getPref.
Director 6.x uses can refer to the sample movie named "FileIO behaviors" on the Director 6.x CD (located in the Goodies > Movies folder). This sample movie contains FileIO Xtra behaviors that you can copy and paste into your own movies.
Reading and writing remote data using postNetText and getNetText
Another method of saving text data from a Director projector or Shockwave movie is to store the data on a remote server. Director's getNetText() and postNetText() functions allow you to do this easily, provided that you have the server-side scripts in place for handling submission of data.
Note: A CGI script running on the server is required to receive the text posted via getNetText() or postNetText() and save it onto the server. Using getNetText() and postNetText() alone can not write text to a server.
GetNetText (6.0.2 and above)
The Lingo command getNetText() performs a standard HTTP GET operation to a URL and retrieves the specified text file resource. You can "post" text to a server-side script using this command by appending data to the URL string (for example, saveText.cgi?data=some%20text%20to%20save). Refer to How do I use getNetText? (14608) for more information.
To ensure that the text downloaded via getNetText() is the latest data available from the server, and not data previously downloaded and stored in cache, append a special character to the end of the URL, as described in How to force getNetText to query server instead on the cache (TechNote 8143).
PostNetText(7.0.2 and above)
Lingo's postNetText() command issues a standard HTTP POST request to a server script, and offers additional capabilities compared to using getNetText(), including the ability to save larger amounts of text then is possible using the GET method. See Using postNetText to send data to a CGI script and the accompanying sample movie for more information. For more information on differences between the POST and GET methods see the article on Hotwired's site, Good Forms.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
