I just figured out how to fix the "supplyFile" bug in Alchemy v0.5.
If you have ever experienced with using "supplyFile" and "fopen" with Alchemy, you may have noticed that using "supplyFile" twice with the same file path won't work if you ever used "fopen" between the two "supplyFile"s.
For example,
In AS3, if you use "supplyFile" twice with the same file path "myfile.txt" but with different ByteArray datas - data0 and data1:
this.cLibInit.supplyFile("myfile.txt", data0);//line A
...
//suppose line C executed
this.cLibInit.supplyFile("myfile.txt", data1);//line B
and try to open the file in C:
//suppose line A executed
FILE *fp;
fp = fopen("myfile.txt","rb");//line C, will open 'data0"
...
//suppose line B executed
FILE *fp2;
fp2 = fopen("myfile.txt","rb");//line D, try to open 'data1", but get ''data0" instead
Only the first "supplyFile" will work and you can only have access to "data0" in C.
This problem happens because once you have used "fopen", the "data0" will be cached in the memory of Alchemy. This is very annoying when you need to change the data for the same path, i.e., when saving game data and then reading them using SharedObject at the runtime.
To fix this problem,we only need to force Alchemy to update when using "fopen".
The solution is simple (yet maybe not optimal):
When compiling for the swc, save the temporary *.as file (something like "XXXX.achacks.as").
Open that ".as" file, search for the function:
private function fetch(path:String):Object
{
var res:Object = statCache[path];
if(!res)
{
var gf:ByteArray = gfiles[path];
if(gf)
{
res = { pending:false, size:gf.length, data:gf };
statCache[path] = res;
return res;
}
}
...
Now, commentize the line "if(!res)", so the patched function will look like this:
private function fetch(path:String):Object
{
var res:Object = statCache[path];
//if(!res)
{
var gf:ByteArray = gfiles[path];
...
Finally, recompile the ".as" file into the swc.
You can find instructions for recompiling the ".as" file to the swc here:
http://bruce-lab.blogspot.com/2011/01/adobe-alchemy-hacks-compile-as-s ource.html
North America
Europe, Middle East and Africa
Asia Pacific