Titanium Community Questions & Answer Archive

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

noobie...click the button question

I'm trying to go to a screen with a click of a button. I just need a little help with the code. This is NOT the code but what I want to have happen…thanks!

b3.addEventListener('click', function()
{
b3.Titanium.UI.createWindow({
url:'examples/foo.js',
title:'foo'
});

— asked March 29th 2010 by Mark Smillie
  • eventlistener
  • iphone
0 Comments

13 Answers

  • Hey Mark,

    Looks like you're close. Something like this should work to open foo.js when b2 is clicked:

    b3.addEventListener('click', function() {
        var win1 = Ti.UI.createWindow({
            url:'examples/foo.js',
            title:'foo'
        });
        Ti.UI.currentTab.open(win1,{animated:true});
    }
    

    It should open foo.js on the current tab. Might have to play around with the path to foo.js.

    — answered March 29th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • Dan, it doesn't work. Nothing happens when I click the button…here is the whole block of code: Thanks.

    var b3 = Titanium.UI.createButton({
    color:'#fff',
    backgroundImage:'assets/BUTT_yel_off.png',
    backgroundSelectedImage:'assets/BUTT_yel_on.png',
    top:110,
    width:301,
    height:57,
    font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
    title:'foo'
    });

    win1.add(b3);

    b3.addEventListener('click', function() {
    var win1 = Ti.UI.createWindow({
    url:'examples/foo.js',
    title:'foo'
    });

    Ti.UI.currentTab.open(win1,{animated:true});
    
    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Dan, it doesn't work. Nothing happens when I click the button…here is the whole block of code: Thanks.

    var b3 = Titanium.UI.createButton({
    color:'#fff',
    backgroundImage:'assets/BUTT_yel_off.png',
    backgroundSelectedImage:'assets/BUTT_yel_on.png',
    top:110,
    width:301,
    height:57,
    font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
    title:'foo'
    });

    win1.add(b3);

    b3.addEventListener('click', function() {
    var win1 = Ti.UI.createWindow({
    url:'examples/foo.js',
    title:'foo'
    });

    Ti.UI.currentTab.open(win1,{animated:true});
    
    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Dan, it doesn't work. Nothing happens when I click the button…here is the whole block of code: Thanks.

    var b3 = Titanium.UI.createButton({
    color:'#fff',
    backgroundImage:'assets/BUTT_yel_off.png',
    backgroundSelectedImage:'assets/BUTT_yel_on.png',
    top:110,
    width:301,
    height:57,
    font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
    title:'foo'
    });

    win1.add(b3);

    b3.addEventListener('click', function() {
    var win1 = Ti.UI.createWindow({
    url:'examples/foo.js',
    title:'foo'
    });

    Ti.UI.currentTab.open(win1,{animated:true});
    
    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Dan, it doesn't work. Nothing happens when I click the button…here is the whole block of code: Thanks.

    var b3 = Titanium.UI.createButton({
    color:'#fff',
    backgroundImage:'assets/BUTT_yel_off.png',
    backgroundSelectedImage:'assets/BUTT_yel_on.png',
    top:110,
    width:301,
    height:57,
    font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
    title:'foo'
    });

    win1.add(b3);

    b3.addEventListener('click', function() {
    var win1 = Ti.UI.createWindow({
    url:'examples/foo.js',
    title:'foo'
    });

    Ti.UI.currentTab.open(win1,{animated:true});
    
    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Try replacing all the code in your page with this, just tried and worked for me:

    var win = Ti.UI.currentWindow;
    win.backgroundColor = '#000';
    var b3 = Titanium.UI.createButton({
        color:'#000',
        top:110,
        width:301,
        height:57,
        font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
        title:'foo'
    });
    win.add(b3);
    b3.addEventListener('click', function() {
        var win1 = Ti.UI.createWindow({
            url:'examples/foo.js',
            title:'foo'
        });
        Ti.UI.currentTab.open(win1,{animated:true});
    });
    
    — answered March 29th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • it runs but it doesn't open any new window. nothing happens. Is there a better way to click a button and have a page load, or go to a new screen/window?

    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • You can also use win1.open() to open the window independent of the tab, but the other way should work fine. It might be that the path to foo.js is off.

    Say you have the code I posted in Resources / examples / test.js. If your foo.js file is also in that folder, change the url to 'foo.js'.

    If that doesn't do it, are you able to zip your resources folder and share it via dropbox, etc.? I'll try running just as you have it and see what happens. Probably something simple.

    BTW which version of the mobile SDK are you using? Latest is 1.1.2

    — answered March 29th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • I've put a zip on box.net http://www.box.net/shared/1jhug4t4pn Much thanks.

    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • I've put a zip on box.net http://www.box.net/shared/1jhug4t4pn Much thanks.

    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Ahhh, okay, I see what's going on. Using Ti.UI.currentTab.open(win1,{animated:true}); works, but not if you're trying to call it from app.js because there technically isn't a tab from the perspective of that code.

    Change line 44 in app.js to win1.open(); and it should open fine, but let me know if it doesn't.

    — answered March 29th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • Rock and roll! it works. Thanks for your help. BTW I'm on 1.1. Seems like there are some RSS issues with this Should I upgrade to 1.1.2?

    — answered March 29th 2010 by Mark Smillie
    permalink
    0 Comments
  • Awesome, glad it's going! Yeah, I'd upgrade to 1.1.2, fixes the parsing plus a few other things.

    — answered March 30th 2010 by Dan Giulvezan
    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.