Here is my most simple code:
var this_version =null;
this.timervar = setTimeout(function () {
try {
// Firefox 4 and later; Mozilla 2 and later
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("parasites@maafire.com", function(addon) {
this_version = addon.version;
alert("r "+this_version);
});
} catch (ex) {
// Firefox 3.6 and before; Mozilla 1.9.2 and before
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var addon = em.getItemForID("parasites@maafire.com");
this_version = addon.version;
alert("rr " + this_version);
}
alert("rrr " + this_version);
}, 2000);
and its so damn strange because this fires twice alert("r "+this_version); but this alert("rrr "+this_version); always gives me null ;(
Still learning JS , so this is pretty puzzling… please help!
Thanks!
Ok, solved it by just moving all the stuff except for the alert out of the timer: