user840248
user840248

Reputation:

AIR, load image stored locally

I package an IPA file including some assets (images). Once installed, I want to load an image in my swf: which is the path of this image? How can I load it?

Upvotes: 3

Views: 3661

Answers (1)

pho
pho

Reputation: 25490

If you packaged your assets folder, the installation should contain its contents in the File.applicationDirectory.resolvePath("./assets/") folder.

You can reference the image file by File.applicationDirectory.resolvePath("./assets/myImage.png")

To read the file to a byteArray,

var f:File=File.applicationDirectory.resolvePath("./assets/myImage.png");
var fs:FileStream=new FileStream();
var ba:ByteArray=new ByteArray();

fs.open(f, FileMode.READ);
fs.readBytes(ba);
//unsure about this, also try CompressionAlgorithm.DEFLATE
ba.uncompress(CompressionAlgorithm.ZLIB); //uncompresses the byteArray
fs.close();

You will now have the bytes of the image file in the byteArray.

Upvotes: 2

Related Questions