Although this discussion is quite old, I thought I'd share my solution in case it helps someone out there.
I came up with a workaround that feels like a bit of a hack, but it gets the job done. Shame on Adobe for not making this easier!
Storing Data as JSON Strings in Menu Data
Menus can persist across page loads, and you can add custom data to a menu. However, it seems to only accept simple data types like strings or integers. To work around this limitation, you can download json2.js from http://json.org and use its `stringify()` and `parse()` functions to convert your application state into a JSON string and store it in the `.data` property of a menu item.
In my case, I stored the JSON string in the first menu item's `items` list. Here's how I did it using jQuery:
function InitApp() {
var menu = air.NativeApplication.nativeApplication.menu;
var firstMenu = menu.items[0];
// Check if data has been stored previously
var dataStore = firstMenu.data;
if (dataStore == null) {
var dataObj = {
msg: "Message Object",
status: 1
};
var dataObjStr = JSON.stringify(dataObj);
firstMenu.data = dataObjStr;
dataStore = firstMenu.data;
} else {
var obj = JSON.parse(dataStore);
}
BuildMenu();
// Pass data along after creating the menu
firstMenu = air.NativeApplication.nativeApplication.menu.items[0];
firstMenu.data = dataStore;
}
$(document).ready(InitApp);
Keep in mind that this data will disappear once the application is closed, as it's only persistent while the app is running.
It would have been much better if NativeApplication supported the same feature as menus!
Note: This code was written on a Mac, so adjustments may be needed for Windows/Linux environments using NativeWindow.menu.