Titanium Community Questions & Answer Archive

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

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

— asked October 21st 2010 by Dan Trevino
  • buttons
  • events
  • windows
0 Comments

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.

    — answered October 21st 2010 by Colton Arabsky
    permalink
    2 Comments
    • Ah, bonehead oversight. Thanks!

      — commented October 21st 2010 by Dan Trevino
    • If we are using Single Window Application template, can we still do this?

      — commented December 24th 2012 by Mario Galvan
  • 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});
    
    — answered October 21st 2010 by Karthikeyan Chandran
    permalink
    2 Comments
    • I'm not using Tabs. I've only created a window and added all buttons to it.

      var win = Ti.UI.createWindow({
      backgroundColor:'white'
      });

      — commented October 21st 2010 by Dan Trevino
    • Hey Dude ,
      I tried it but its not working .

      thanks for you time in advance.

      var mainWindow = Titanium.UI.createWindow({
          backgroundColor:"#CCC",
          layout:'vertical'
      
      });
      
      var btn = Titanium.UI.createButton({
          title:'Click me',
          height:'100',
          width:'300',
      
      });
      
      btn.addEventListener("click",function(eventObject){
      
          var newWindow = Titanium.UI.createWindow({
              title:'New Window',
              backgroundColor:'#AAA',
      
          });
      
          Ti.UI.currentWindow.open(newWindow);
      });
      
      mainWindow.add(btn);
      mainWindow.open();
      

      — commented February 16th 2012 by Hikmat Khan
  • NOTE

    I know this question was asked 11month ago but may be my answer will help to new one.

    1. 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.
    — answered December 18th 2012 by Darshana Patil
    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.