------------------------------------------------ -- These handlers work best in a movie script. - -- Ken Loge - http://diginoodles.com - ------------------------------------------------ -- OPEN A TEXT FILE on openFile fileName if objectP(_global.gFile) then set _global.gFile = 0 -- delete the instance if it already exists _global.gFile = new(xtra "fileio") -- create an instance of FileIO openFile(_global.gFile,the moviePath & fileName,1) -- Open the file with read access myVariable = readFile(_global.gFile) if readFile(_global.gFile) = VOID then -- checks to see if this file exists alert "UH OH - The file" && quote &fileName& quote && "could not be found." -- alerts if the variable returned VOID else tempData = string(myVariable) -- copy file data to a text member closeFile(_global.gFile) -- close the file end if -- gLogFile = 0 -- dispose of the instance return tempData end -- OPEN A TEXT FILE FROM A USER SPECIFIED PATH on openAndReadText fileObj = new(xtra "fileio") -- create an instance of FileIO -- set the filter mask to text files if the platform contains "mac" then fileObj.setFilterMask("TEXT") else fileObj.setFilterMask("Text Files,*.txt,All Files,*.*") end if -- open dialog box filename = fileObj.displayOpen() -- check to see if cancel was hit if filename = "" then return "" -- open the file fileObj.openFile(filename,1) -- check to see if file opened ok if fileObj.status() <> 0 then err = fileObj.error(fileObj.status()) alert "Error:"&&err return "" end if -- read the file text = fileObj.readFile() closeFile(fileObj) -- close the file --return the text return text end -- SAVE A TEXT FILE TO A USER SPECIFIED PATH on saveText text fileObj = new(xtra "fileio") -- create an instance of FileIO -- set the filter mask to text files if the platform contains "mac" then fileObj.setFilterMask("TEXT") else fileObj.setFilterMask("Text Files,*.txt,All Files,*.*") end if -- save dialog box filename = fileObj.displaySave("","") -- check to see if cancel was hit if filename = "" then return FALSE -- delete existing file, if any fileObj.openFile(filename,2) fileObj.delete() -- create and open the file fileObj.createFile(filename) fileObj.openFile(filename,2) -- check to see if file opened ok if fileObj.status() <> 0 then err = fileObj.error(fileObj.status()) alert "Error:"&&err return "" end if -- write the file fileObj.writeString(text) -- set the file type if the platform contains "Mac" then fileObj.setFinderInfo("TEXT ttxt") end if -- close the file closeFile(fileObj) return TRUE end