Use redefined function in every opened window
Hello everybody. I am trying to make a orientationchange listener that uses a specific function for the current window, and this function should be redefined in every .js opened as a window.
The code looks something like this:
app.js
var win = Titanium.UI.createWindow({
url:'prod_win.js'
});
Ti.Gesture.addEventListener('orientationchange',function(e) {
Ti.API.info('orientationchange event');
var win = Titanium.UI.currentWindow;
win.a();
});
_prodwin.js
var win = Titanium.UI.currentWindow;
win.a = function() {
alert('b');
}
win.a();
The call in the prod_win.js for the function win.a() happens with no problem, but the one from the trigger gives this error: "Result of expression 'win' [null] is not an object.";
Can someone tell me what I am doing wrong?
Thanks in advance.
Vali.
5 Answers
-
Bump
-
Yet again. Please help me figure this out, because it would clean a lot of duplicate code that I have copied to make this work…
-
I dont know for sure, but why are you defining "win" in your app.js twice?
-
I believe Titanium.UI.currentWindow will be null if it is called within app.js. Are you seeing info in the console about a rotation but get an error about win being nil or win.a is not a function?
-
it looks like there is bug in Ti.Gesture.addEventListener('orientationchange',function(e) {}); scope.
you can't get current window from inside this event function. (don't get confused if it sometimes works. its because you can get this right just for one window what is active at the time of creating this event listener. but change of current window is not reflected)
my related question