Launch new Window From Button error
I'm trying to launch a new window from a button click event. Relevant error message, code, and trace is in the pastie below.
http://pastie.org/1237236
Basically, the button click event listener creates a new window, and opens it. But I keep getting a "cannot call method "open" on null" error. I see an object created (see pastie), so the window is there, but open fails.
This is the same technique used from tableviews in KitchenSink.
Why might this not be working from a button?
dan
3 Answers
-
Accepted Answer
var eventsButton = Titanium.UI.createButton({ color:'#fff', backgroundImage:'imgs/button_112x112.png', top:80, left: leftCol, width: 112, height: 112 }); eventsButton.addEventListener('click', function() { Ti.API.info('event button clicked') var eventWin = Ti.UI.createWindow({ url:'event.js', title:'Events' }); Ti.API.info('eventwin in app.js: ' + eventWin); eventWin.open(); }); win.add(eventsButton); win.add(buttonLabel);
Gotta use "eventWin.open();". That'll open the new window, with the option of using a modal or another type of animation.
-
Hi,don`t use the function
Ti.UI.currentWindow.open(eventWin,{animated:true});
instead of that use the current tab to open new window,
Titanium.UI.currentTab.open(eventWin,{animated:true});
-
NOTE
I know this question was asked 11month ago but may be my answer will help to new one.
- We cannot open 2nd window upon 1st window
2. Solution is we can create separate JS file with 2nd window and all it on button click.
- We cannot open 2nd window upon 1st window