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'
});
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.
-
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});
-
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});
-
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});
-
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});
-
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}); });
-
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?
-
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
-
I've put a zip on box.net http://www.box.net/shared/1jhug4t4pn Much thanks.
-
I've put a zip on box.net http://www.box.net/shared/1jhug4t4pn Much thanks.
-
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.
-
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?
-
Awesome, glad it's going! Yeah, I'd upgrade to 1.1.2, fixes the parsing plus a few other things.