Nav Bar at top but not firing properly?

You must Login before you can answer or comment on any questions.

I have created a real basic nav bar at the top so i wouldn't have to mess with the tab functions at the bottom.
I have 2 questions. I am first of all having problems trying to reference the extensions of .js files via url. See code. It says that it does not pull up properly. So I went ahead and added functions and added the module.exprts to (tibook). So when i try and pull up tibook. I then get a scripting error saying that it can't find the variable.

So to recap it's not pulling up my ***.js files once i click on the nav bar at the top. And if it does pull it up i get a scripting error.

In this forum you see the app.js file along with the book.js file.

This is the main area here (app.js)

var win = Titanium.UI.createWindow({

// backgroundColor : 'white'

});

var tb1 = Titanium.UI.createTabbedBar({

labels : ['Sports', 'Map', 'Books', 'Contact'],

backgroundColor : '#336699',

top : 0,

style : Titanium.UI.iPhone.SystemButtonStyle.BAR,

height : 40,

width : '100%',

index : 1,

});

win.add(tb1);

var newWin = Ti.UI.createWindow({

url : 'book.js'

});

tb1.addEventListener('click', function(e) {

if(e.index == 0) {

    var newWin = Ti.UI.createWindow({

        url : 'book.js',

        top : 41

    });

    newWin.open();

}

if(e.index == 1) {

    var newWin = Ti.UI.createWindow({

        url : 'info.js',

        top : 41

    });

    newWin.open();

}

if(e.index == 2) {

    var newWin = Ti.UI.createWindow({

        url : 'map.js',

        top : 41

    });

    newWin.open();

}

if(e.index == 3) {

    var newWin = Ti.UI.createWindow({

        url : 'galary.js',

        top : 41

    });

    newWin.open();

}

})

win.open();

//var win = Titanium.UI.createWindow({

// title:"tittle",
// backgroundColor:"#FFFFFF",

//})

var label = Titanium.UI.createLabel({

backgroundImage: "images/what.png",

top: "10%",

width: "100%",

height: "12%",

textalign: "center",

})

// new button

var openWebpagenotification = Titanium.UI.createButton({

title:"Notifications",

backgroundImage: "images/notificationbutton.png",

width:"100%", 

height:"12%",

top:"20%",

id: "Notifications",

url:"http://www.google.com/",             color: '#000000'                                                        

});

openWebpagenotification.addEventListener("click", function(e){

// Create a window and add a webview to it that opens your url:

var webviewWindow = Titanium.UI.createWindow({title: 'Notifications', fullscreen: false});

var myWebView = Ti.UI.createWebView({url:e.source.url});

webviewWindow.add(myWebView);

// Will need a button to close the new window:

var closeButton = Titanium.UI.createButton({title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN});

webviewWindow.setLeftNavButton(closeButton);

closeButton.addEventListener('click',function(evt){

webviewWindow.close();

///////////////////////////////////////////////////////////////////////////////////// This is the book.js file.*************

function tibook() { var win = Titanium.UI.createWindow(); var win = Titanium.UI.createWindow({ // backgroundColor : 'white' });

var tb1 = Titanium.UI.createTabbedBar({ labels : ['Sports', 'Map', 'Books', 'Contact'], backgroundColor : '#336699', top : 0, style : Titanium.UI.iPhone.SystemButtonStyle.BAR, height : 40, width : '100%', index : 1, }); win.add(tb1);

var newWin = Ti.UI.createWindow({ url : 'book.js' });

tb1.addEventListener('click', function(e) { if(e.index == 0) { var newWin = Ti.UI.createWindow({ url : 'book.js', top : 41 }); newWin.open(); } if(e.index == 1) { var newWin = Ti.UI.createWindow({ url : 'geo.js', top : 41 }); newWin.open(); } if(e.index == 2) { var newWin = Ti.UI.createWindow({ url : 'map.js', top : 41 }); newWin.open(); } if(e.index == 3) { var newWin = Ti.UI.createWindow({ url : 'galary.js', top : 41 }); newWin.open(); } })

win.open();

return win; };

module.exports = tibook;

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Now I get a script errro and it says it can't find vairale : module at book.js

I thought the code was right, but obviously not :). all I am doing is referencing a simple screen. Any thoughts with that?

});

Thanks for your help in advance. -Paul

2 Answers

Well, first of all, you are mixing url: calls with commonJS exports.

Thats not going to work at all.

— answered 10 months ago by Stephen Feather
answer permalink
3 Comments
  • Using the code in your book.js, you call should be more like this: And removing the win.open() from book.js

    var BookWindow = require('book');
    var bookWindow = new BookWindow();
    bookWindow.open();

    — commented 10 months ago by Stephen Feather

  • That seems to have worked and I'm not geting a red screen error anymore. :) But shouldn't it be coming up as nothing in that tab?

    I was hoping to make a list of books for example with some simple html code, but i still see the main screen from app.js file when I click on the book tab for example. This is the code as it looks now for the book.js file so others can follow along with us.

    function tibook() { var BookWindow = require('book'); // suggested by stephen feather - much thanks to him var BookWindow = new BookWindow(); bookWindow.open();

    //var win = Titanium.UI.createWindow(); //var win = Titanium.UI.createWindow({ // backgroundColor : 'white' //});

    var tb1 = Titanium.UI.createTabbedBar({ labels : ['Sports', 'Map', 'Books', 'Contact'], backgroundColor : '#336699', top : 0, style : Titanium.UI.iPhone.SystemButtonStyle.BAR, height : 40, width : '100%', index : 1, }); win.add(tb1);

    var newWin = Ti.UI.createWindow({ url : 'book.js' });

    tb1.addEventListener('click', function(e) { if(e.index == 0) { var newWin = Ti.UI.createWindow({ url : 'book.js', top : 41 }); newWin.open(); } if(e.index == 1) { var newWin = Ti.UI.createWindow({ url : 'geo.js', top : 41 }); newWin.open(); } if(e.index == 2) { var newWin = Ti.UI.createWindow({ url : 'map.js', top : 41 }); newWin.open(); } if(e.index == 3) { var newWin = Ti.UI.createWindow({ url : 'galary.js', top : 41 }); newWin.open(); } })

    win.open();

    return self;
    

    };

    //module.exports = tibook;

    //////////////////////

    So that's all the code now in the book.js file. I thought for some reason it should have a blank screen, because as you can see there is nothing in there besides the nav bar up top. Thanks for any thoughts. - paul

    ps: how do you do the code like that in black?

    — commented 10 months ago by paul wamser

  • Hi Stephen, Now when i do this... I left app.js the same as above.

    But i put this in the book.js file and took out the rest.

    var bookWindow = require('book');
        var bookWindow = new bookWindow();
        bookWindow.open();
    And that was the only code that I have in there now at all in the book.js. I get this error.

    Test[22613:1b803] *** Terminating app due to uncaught exception of class '__NSCFDictionary' terminate called throwing an exception

    Any thoughts would be greatly appreciated. Thanks!

    — commented 10 months ago by paul wamser

I even tried it like this as well....

function tibook() {
    var bookWindow = require('book');
    var bookWindow = new bookWindow();
    bookWindow.open();
 
 
        return win;
};
Now i don't get an eror with this, but i still see the main screen from the app.js file. I would like to be able to pull up just a list of books that i can input there myself. thanks for your thoughts. regards, -paul

Your Answer

Think you can help? Login to answer this question!