Created
May 25, 2012 02:34
-
-
Save davidortinau/2785434 to your computer and use it in GitHub Desktop.
Writing JSON-style info to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { (function() { | |
if (!fw.selection || !fw.selection.length) { | |
return; | |
} | |
var json, filePath, file; | |
json = '{"sprites":['; | |
for(i=0;i < fw.selection.length;i++){ | |
var element = fw.selection[i]; | |
json += '{"key":"' + element.baseName + '","bounds":{"x":' + element.left + ',"y":' + element.top + ',"width":' + element.width + ',"height":' + element.height + '}},'; | |
}; | |
json = json.slice(0, json.length-1); | |
json += ']}'; | |
filePath = fw.browseForFileURL("save"); | |
if (!filePath) { | |
return; | |
} | |
Files.deleteFileIfExisting(filePath); | |
Files.createFile(filePath, "TEXT", "????"); | |
file = Files.open(filePath, true); | |
file.write(json); | |
file.close(); | |
})(); } catch (exception) { | |
if (exception.lineNumber) { | |
alert([exception, exception.lineNumber, exception.fileName].join("\n")); | |
} else { | |
throw exception; | |
} | |
} |
fixed name by changing it to baseName
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample result has null "name" values.
{"sprites":[{"key":null,"bounds":{"x":42,"y":0,"width":50,"height":34}},{"key":null,"bounds":{"x":0,"y":0,"width":42,"height":34}}]}