|
|||
|
Hello SWFKit!
I have been having some troubles with saving using Flash CS3 + SWFKit Pro 3.4. When i try and save an object to a text file, it takes an incredibly long time to save, causes Flash to hang, and eventually brings up (after the allotted 60 seconds script time out) a time out window. If i press no, do not abort script - it immediately saves, and the program begins working normally. Any ideas? This is roughly the code that i use... Code:
function save(){
didItSave = false;
objV = {details:details, Settings:settings, training:training, individual:individual};
swfKitSave(objV);
}
function swfKitSave(obj,fileType,fileTypeShort){
var filename = Dialogs.fileSave(fileType);
if(filename){
strace("save, filename = " + filename);
if (filename.substr(-fileTypeShort.length,fileTypeShort.length)!=fileTypeShort && filename.substr(-fileTypeShort.length,fileTypeShort.length)!=fileTypeShort) {
filename = filename + fileTypeShort;
}
SDWriter.write(filename, obj);
}
}
Code:
import SWFKit.*;
class SDWriter {
// primary types
public static var BOOLEAN_TYPE = 0;
public static var NULL_TYPE = 1;
public static var NUMBER_TYPE = 2;
public static var OBJECT_TYPE = 3;
public static var STRING_TYPE = 4;
public static var UNDEFINED_TYPE = 5;
public static var ARRAY_TYPE = 6;
public static var UNKNOWN_TYPE = 7;
public static function write(filename, value) {
var fileStream = new FileStream(filename, "w");
if (fileStream == null) return false;
writeValue(fileStream, value);
fileStream.Release();
return true;
}
private static function writeString(fileStream, value) {
fileStream.write(value);
fileStream.put(0);
}
private static function writeValue(fileStream, value) {
var type = typeof(value);
if (type == 'string') {
fileStream.put(STRING_TYPE);
writeString(fileStream, value);
} else if (type == 'undefined') {
fileStream.put(UNDEFINED_TYPE);
} else if (type == 'number') {
fileStream.put(NUMBER_TYPE);
// the value can be either an integer or a double, so convert it to string
writeString(fileStream, value.toString());
} else if (type == "null") {
fileStream.put(NULL_TYPE);
} else if (type == "boolean") {
fileStream.put(BOOLEAN_TYPE);
fileStream.put(value ? 1 : 0);
} else if (value instanceof Array) {
fileStream.put(ARRAY_TYPE);
fileStream.write(value.length);
for (var i = 0; i < value.length; i++) {
var v = value[i];
writeValue(fileStream, v);
}
} else if (type == "object") {
fileStream.put(OBJECT_TYPE);
for (var i in value) {
writeValue(fileStream, i);
writeValue(fileStream, value[i]);
}
// end of object
writeValue(fileStream, false);
} else {
fileStream.put(UNKNOWN_TYPE);
}
}
}
dmb |
|
|||
|
We cannot make your code work, can you send us a .fla file to support@swfkit.com? Thank you very much.
|
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|