2 Replies Latest reply on Feb 21, 2010 8:04 PM by aliandri

    load RTF file to Text sprite

    aliandri

      Hi, everyone....

      i try learning lingo on folder macromedia and i found this script :

       

      on readFile

        -- the file path needs to be the same one you wrote to

        filePath = _movie.path & "demoSaveFile"

        -- create a new instance of the fileIO Xtra

        fileIOInstance = xtra("FileIO").new()

       

        -- error trap for missing file Xtra

        if not fileIOInstance.objectP then

          _player.alert("File IO Xtra missing")

          exit

        end if

       

        -- open the file for reading

        fileIOInstance.openFile(filePath, 0)

       

        -- status is a value returned by the fileIO Xtra reporting the status of the last FileIO command executed.

        -- in this case it's the result of executing "openFile(fileIOInstance, filePath, 0)"

        if fileIOInstance.status() = 0 then

          -- the open was sucessful so read the file and then close it

          fileText = fileIOInstance.readFile()

          fileIOInstance.closeFile()

          -- display the text on stage.

          member("file contents").text = fileText

        else

          -- if there was an error display the error message on stage.

          member("file contents").text = "Error: " & fileIOInstance.error(fileIOInstance.status())

        end if

      end

       

      it's work if that file it's nothing parameter like inside file RTF but if i load file RTF and all parameter it's load to Text Sprite.....

       

      Can help me ?

        • 1. Re: load RTF file to Text sprite
          Sean_Wilson Adobe Community Professional

          It's not completely clear what you're asking, but I'll assume (from the title) that you're wanting to load RTF from a file on your HDD into a #text member. Like everything in Director, there's more than one way to skin a cat. The simplest solution is the following, which assumes there's a file name "text.rtf" in the same folder as the Director movie:

          -- attached to a button or similar:
          -- you need a text member in your cast library named "text"
          on mouseUp me
            member("text").filename = "@/text.rtf"
          end
          

           

          An alternative is to alter what you posted already (I'll focus just around the lines that need changing, the rest can stay like it is):

            -- ...
            if fileIOInstance.status() = 0 then
              -- the open was sucessful so read the file and then close it
              fileText = fileIOInstance.readFile()
              fileIOInstance.closeFile()
             
              -- display the text on stage.
              member("file contents").rtf = fileText -- CHANGED HERE
            else
            -- ...
          
          • 2. Re: load RTF file to Text sprite
            aliandri Level 1

            All It's work...

            but

            i choose simple instruction  like :

            - attached to a button or similar:
            -- you need a text member in your cast library named "text"
            on mouseUp me
              member("text").filename = "@/text.rtf"
            end

            Thank you for your attention.....