javascriptdom-eventsappceleratortitanium-mobileappcelerator-mobile

Add event listener to Titanium


I'm new to Titanium and Web programming and Mobile apps. I want to make simple event listener. When I click the image another window opens. The other windows must be an external .js file

var image=Ti.UI.createImageWiew({
image:'...............',
 })


image.addeventListener('click',function(){

//what do I write here?

 )

Solution

  • Write this code inside your listener:

    image.addeventListener('click',function(){
        var window = Ti.UI.createWindow({
             url:'external.js' 
        });   
        Ti.UI.currentTab.open(window,{animated:true});
    
    });
    

    And write this code inside your external.js file:

    var window = Ti.UI.currentWindow;
    window.backgroundImage = 'your-bg-image';
    

    If you are opening a window using url, you can't do this:

    var win=Ti.UI.createWindow({ });
    

    inside your js file.