Reputation: 488
I am trying to go back to the old window/ move to new window but getting a error,previously it was working fine until now getting a new error
Uncaught TypeError: object is not a function
Here is my code: app.js
var win = Titanium.UI.createWindow({
title : 'my app',
backgroundColor : '#fff',
fullscreen : false,
navBarHidden : true,
layout : 'vertical'
});
submitbtn.addEventListener('click', function(e) {
var createnewWindowback = require('ui/page1');
new createnewWindowback().open();
win.close();
});
page1.js
var win = Titanium.UI.createWindow({
title : 'my app',
backgroundColor : '#fff',
fullscreen : false,
navBarHidden : true,
layout : 'vertical'
});
win.addEventListener('android:back', function(e) {
var createnewWindowback = require('app');
new createnewWindowback().open();
win.close();
});
Plz help
Upvotes: 0
Views: 288
Reputation: 2807
First, let me admit that I use Alloy instead for all my windows handling - so that is slightly different. But I do use CommonJS modules for all my logic.
Basically, if you use a CommonJS module you will need to put it in a "lib" folder in your project. So the libraries you are referring to should be in:
lib/ui/app.js
lib/ui/page1.js
for your require statements to find them. So this could be the first place to check.
Then you will have to tell the CommonJS module what you will let the "outside" call/"know" from the inside of your module. You will do this using the one of:
exports.myMethod = function() {....}
module.exports = MyObject
Only in the latter example will you be able to write something like
new createnewWindowback().open();
So obviously, your code will fail at this statement if not at the require :-)
Next, your "object" will have to implement a method "open()" for it to work.
I suggest that you have a look at the Appcelerator University videos - and download the Kitchen Sink app and have a look at the code.
/John
Upvotes: 1