4

I want to embed static text, basically for a help file. Something like

const help:String = "This is a help line.";

except for it would get it from a file?

const help:String = //retrieve text from a static file
Timmy
  • 12,468
  • 20
  • 77
  • 107

1 Answers1

10

Here's a quick example:

public class EmbedText extends Sprite
{

    [Embed(source="textfile.txt",mimeType="application/octet-stream")]
    var myText:Class;

    public function EmbedText ()
    {           
        var txt:ByteArray = new myText() as ByteArray;
        trace(txt.toString());          
    }
}

This will include the file 'textfile.txt' into your SWF at compile-time. If you want to load the text-file from the server at run-time, you should instead use the URLLoader class.

davr
  • 18,877
  • 17
  • 76
  • 99
  • Is there a way to do this without creating a local field? Like so it can be accessed by filename, but without putting it in the Assets folder? – Patrick May 30 '17 at 19:06