Okay, I realize this thread is OLD but if it helps someone.
My solution feels like a complete hack - shame on Adobe - but it works.
Store the data as JSON strings in the menu data
Menus persist across page loads, and you can assign a custom data to a menu. So far it seems to only like simple data types, like strings or ints. So the solution is to download json2.js (http://json.org) and use it's stringify()
and parse()
commands to convert your application state into a JSON string then store that in the .data
member of a menu.
I stored it in the first menu. in the items
list.
Using jQuery
, my application code looked like this:
function InitApp() {
// check before we create the menu for the very first time.
var menu = air.NativeApplication.nativeApplication.menu;
var firstMenu = menu.items[0];
var dataStore = firstMenu.data;
if (dataStore == null) {
air.trace("Create Menu Data Store");
var dataObj = {
msg: "Message Object",
status: 1
};
var dataObjStr = JSON.stringify(dataObj);
firstMenu.data = dataObjStr;
dataStore = firstMenu.data;
air.trace("Created menu data store");
air.trace(dataObjStr);
} else {
var dataStore = firstMenu.data;
var obj = JSON.parse(dataStore);
air.trace("Retrieved Menu Data Store");
air.trace(obj.msg);
}
BuildMenu();
// check after we create our menu
firstMenu = air.NativeApplication.nativeApplication.menu.items[0];
firstMenu.data = dataStore; // pass it along.
}
$(document).ready(InitApp);
This data vanishes when the application is closed, so it is only persistent while the app is open.
The real answer would have been for nativeApplication to support the EXACT SAME FEATURE as the menus!
Note: I wrote this on a Mac, so you'd have to adjust the code for using NativeWindow.menu for windows / linux.