Can someone help me on this issue? It works perfectly on iOS but crashes on Android. As soon as you click the button, you get the error "Message: ReferenceError: "namespace" is not defined. (file:///android_asset/Resources/testTwo.js#2)".
This error does not occur if test.js is a light weight window. However we have to make it heavyweight as it is the main window so we can exitOnClose as well as intercept the back button as necessary.
I'm using Android API 2.3 using Titanium SDK 1.7.2.
//app.js var namespace = {}; namespace.printout = function(){ Ti.API.info('namespace.printout'); }; Ti.include('/test.js'); var win = namespace.test(); win.open();
//test.js (function(){ namespace.test = function(){ var winTest = Titanium.UI.createWindow({ title: 'Test', backgroundColor: '#fff', exitOnClose: true, fullscreen: false // making this a heavy weight window }); var btnButton = Ti.UI.createButton({ title: 'Click button', width: 150, height: 100, top: 100 }); btnButton.addEventListener('click', function(){ Ti.include('/testTwo.js'); var winToOpen = namespace.testTwo(); winToOpen.open(); }); winTest.add(btnButton); namespace.printout(); return winTest; }; })();
//testTwo.js (function(){ namespace.testTwo = function(){ var winTestTwo = Titanium.UI.createWindow({ title: 'Test2', backgroundColor: '#fff' }); var btnBack = Ti.UI.createButton({ title: 'back', height: 100, width: 100, top: 50 }); btnBack.addEventListener('click', function(){ winTestTwo.close(); }); winTestTwo.add(btnBack); return winTestTwo; }; })();
2 Answers
Accepted Answer
ok had a quick look, nice coding, however I think the issue is including the files. The actual path of files work differently on iOS and android, although it is a lot better in 1.7.2 and 1.8 sdk,s.
using / to define the file location is not they way. Try removing this in front of the included file and if this does not work actually put the path in relative to the actual calling file ovation.
hope this helps.
IMHO, files are loaded asynchronously and that's why you shouldn't include files and use included variables/functions just after that. I use function constructors in included files and I include them on top of the script. Then I can safely use staff from included file in the script.
Your Answer
Think you can help? Login to answer this question!