Android fails to call global function from subcontext
I'm trying to give subcontext windows access to values in the global context, according to the documentation in the Titanium.UI.Window API reference document. It works seemingly OK on iPhone, but not on Android. Any help would be appreciated!
app.js:
function x() { return 123; }
var win = Ti.UI.createWindow({ url:'win.js' });
win.x = x;
win.open();
win.js:
var label = Ti.UI.createLabel({ text:Ti.UI.currentWindow.x() });
Ti.UI.currentWindow.add(label);
Running this on iPhone produces the expect result: a page displaying the number "123." Running this on Android produces the following error:
TypeError: Cannot call property x in object ti.modules.titanium.ui.WindowProxy@43ddc0e8. It is not a function, it is "object". (app://win.js#10197)
3 Answers
-
The ability to assign objects in a window from the global context appears to be an iPhone-only feature.
Passing data between windows on Android needs to be done differently, but I'm not sure how. For instance, if I have a global user id that I need to pass to a window that handles taking in user input and posting it up to a server, I'm not sure how to get that user id into the window context in Android. That's a separable question, though, which I've opened here
-
Any news about this problem?
-
This works for me, check the log console for function output
// app.js function x() { return 123; } var win = Ti.UI.createWindow({ x:x, title:'Test Window', url:'win.js', width:'100%', height:'100%' }); win.open();
new window context
// win.js Ti.API.info("initializing tabwin"); var currentWin = Ti.UI.currentWindow; Ti.API.info("initializing tabwin " + currentWin.x());