Import and export RTF files without having to pay for extras.
Basically use the exact same demo as that which comes with the FileIOXtra but change a few things.
-- Saving out to a file.
on saveText (whichmember)
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- set the filter mask to text files
if the platform contains "mac" then
setFilterMask(fileObj,"TEXT")
else
setFilterMask(fileObj,"Text Files,*.txt,All Files,*.*")
end if
-- save dialog box
filename = displaySave(fileObj,"","")
-- check to see if cancel was hit
if filename = "" then return FALSE
-- delete existing file, if any
openFile (fileObj,filename,2)
delete(fileObj)
-- create and open the file
createFile(fileObj,filename)
openFile(fileObj,filename,2)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return FALSE
end if
-- write the file
TextToSave=member(whichmember).rtf -- .rtf indicates the rich text format of the cast member.
writeString(fileObj, TextToSave)
-- so the text file will contain the rtf data. A regular text editor will open it with junk
-- but any application that supports .rtf files will understand the formatting.
-- set the file type
if the platform contains "Mac" then
--instead of the following, setFinderInfo should contain
--the necessary information for an rtf file. I am a PC person and
--do not know what the Mac Finder info is for rtf files.
--setFinderInfo(fileObj, "TEXT ttxt")
end if
-- close the file
closeFile(fileObj)
return TRUE
end
-- Loading from a file into member(whichmembertosaveto)
on LoadText (whichmembertosaveto)
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- set the filter mask to text files
if the platform contains "mac" then
-- setFilterMask(fileObj,"RTF")
--the mac FilterMask should be set to whatever "RTF" Files are. Again, I am a PC person.
else
setFilterMask(fileObj,"RTF Files,*.RTF,All Files,*.*")
end if
-- open dialog box
filename = displayOpen(fileObj)
-- check to see if cancel was hit
if filename = "" then return ""
-- open the file
openFile(fileObj,filename,1)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return ""
end if
-- read the file
text = readFile(fileObj)
-- close the file
closeFile(fileObj)
--put the rtf data into a member
member(whichmembertosaveto).rtf=text
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA