Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked March 30th 2010 by Dan Duke
  • android
  • basic
  • beginner
  • button
  • link
  • navigation
  • win32
0 Comments

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;
    });
    
    — answered March 31st 2010 by Dan Duke
    permalink
    0 Comments
  • You need to create a window in your onclick.

    mapButton.addEventListener('click', function(e)
    {
       var win = Ti.UI.createWindow(url : 'map.js');
        win.open();
    });
    
    — answered March 30th 2010 by Don Thorp
    permalink
    0 Comments
  • 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?

    — answered August 11th 2010 by Jonathan Bardi
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.