Navigating with buttons
I am playing around with Titanium, and really hope to get a good grasp of it soon, but am currently getting confused with how to navigate between .js files.
I understand how to use tabs, but for my file I would like a few buttons positioned within the window and on click to link to a js file. I tried something like:
var mapButton = Titanium.UI.createButton({
title: 'Map',
width:200,
height:40,
top:60,
url:'map.js'
});
mapButton.addEventListener('click',function(e)
{
Titanium.API.info("Map");
});
But it refuses to work, I get the Ti output, but it doesn't change pages. I'm not even getting an error.
I also tried using:
window.location = 'map.js'
But again nothing happened, could this mean an error on map.js, or am I just getting confused with the navigation setup?
3 Answers
-
Thankyou Don, I had to slightly tweak your code as I was getting an error. I believe I need curly brackets for the variables. So I put them in, it got ri of the error. But sadly clicking the button didn't open the window (although it still ran the info() function).
So I tried to use Titanium.UI.currentWindow (as I already have a window open, so figured maybe it just needs me to switch windows), but still no change.
mapButton.addEventListener('click', function(e) { Titanium.API.info("Map"); var win = Titanium.UI.createWindow({url:'map.js'}); //win.open(); Titanium.UI.currentWindow = win; });
-
You need to create a window in your onclick.
mapButton.addEventListener('click', function(e) { var win = Ti.UI.createWindow(url : 'map.js'); win.open(); });
-
I had the same problem, and have 2 windows, win1 and win2. Both window objects have been created, win2 with the url attribute pointing to my second JS file. Issuing win2.open() on my button event works to get me to the second window, but now how do I get back to win1?
In the win2 there is no reference to the previous or parent window win1, so how do I have a button on win2 move me back to win1?