Saturday, October 3, 2009

Import Insert Read - Text File to Flex TextArea

Now you can easily Import/Insert/Read any Text File contents to Flex TextArea and Display it with each and every line indentation in place.

With this, you can import Text File (even .htm content) seamlessly into Flex TextArea if the file is viewable in Notepad. It really works for any text file [.txt, .htm, .xml, .as, .js or any other that you may have]

Typically, this is a standard SWF file that gets generated as you compile the code in Flex 3 SDK. You can freely download the complete mxml code at
Download ReadTextFile.zip

Do let me know if you find any problem.

You can even use \\ to point to text file location. Example: C:\\WINDOWS\\system32\\oobe\\iconnect.js'. However, to do this, you have to add "-use-network=false" to Flex Compiler additional arguments before compilation.

Hope you find it useful. Code image is down below.

Ciao

3 comments:

  1. Hi there,

    I used your code to read from a .txt file and it works fine. However, how do i modify this so that it recognises the content within the .txt as html text.

    You can see what I mean by looking at my example:

    http://www.enemypoets.com/flex/News/ReadTextFile.html

    Thanks in advance.

    Mike.

    ReplyDelete
  2. Hi Mike,

    I checked the link you referred to. It's doing what it's designed to do - that's reading the file text content As Is - including the HTML tags as valid characters. If you need to identify the text as HTML text, the code needs to trace out the presence of major HTML keywords and/or impart a few specific conditions so that it can be differentiated from say an XML data, MXML code or any other text which contain similar notations. You may write to blogs.sid@gmail.com for further specifics.

    Cheers.

    Sid

    ReplyDelete
  3. This worked perfectly for me! So glad to find it in a google search!

    jess

    ReplyDelete