views:

111

answers:

3

I just started learning ActionScript, so maybe this is obvious. I'm loading in .txt files to generate content for my Flash application. However, I can't seem to find a way to package the .txt files with the .swf when I publish my application. I'd like to be able to run the .swf from anywhere without it depending on the files. Is there a solution for this?

Thanks!

A: 

Try loading .as files, with variables defined inside them. They're, technically, still text files and still easy to edit, but they get automatically encapsulated in the .swf.

In your main stage, you just add include 'included.as';. In your included.as file, you just define whatever variables you want, for example:

var someData:Array = new Array();
someData.push('This is some string');
someData.push('This is some other string');

After you include the as, you can call whatever variable you defined. And when you export, the .as file is embedded into the .swf.

evilpenguin
+2  A: 

Hi, this is an excellent post by Emanuele Feronato:

how-to-embed-a-text-file-in-flash

Basically you use the embed syntax to embed the file as a ByteArray. The key method here is to call the toString() method on the ByteArray to convert to a string.

Hope this helps

A: 

Even better then just embedding a .txt with your flash, if you're more versed with programming I would suggest you to create a static class to store the values of your application. Just like:

class StaticData {

    static public var siteTitle:String = "My site name";
    static public var homeMessage:String = "Lorem Ipsum dolor sit amet...";
    static public var welcomeMessage:String = "Hello World";

    static public var siteWidth:Number = 1024;
    static public var siteHeight:Number = 780;

}

This is a safe and realiable way to store static values using a simple class structure, to use a value from the class, you just need to call inside your flash:

my_textfield.text = StaticData.siteTitle;
my_shape.width = StaticData.siteWidth;
ruyadorno