navyad
navyad

Reputation: 3860

on event call another js file having new window

i developing sample android application in Titanium. on home window(app.js) it has some buttons ,now what i want is on the click of each button app.js(home window) must call another javascript file (they will create new window of their own.

but.addEventListener('click', function(e){

    call another .js file which will open new window
})

will appreciate some guidance

Upvotes: 0

Views: 1809

Answers (5)

Nagaraja
Nagaraja

Reputation: 581

var All = require('ui/common/All');

    Tree = require('ui/common/Tree');

    EBOM = require('ui/common/E-BOM');

    MBOM = require('ui/common/M-BOM');

    SBOM = require('ui/common/S-BOM');

//create object instance

var self = Ti.UI.createWindow({

    title:'Products',

    exitOnClose:true,

    navBarHidden:true,

    backgroundColor:'#ffffff',
    /////////////////////////////////////////////////////////////////////////////

    activity: {

        onCreateOptionsMenu: function(e) {

            var menu = e.menu;                        

            var menuItem = menu.add({ title: "C-BOM", icon: 'Arrow-Hover.jpg' });

            //menuItem.setIcon("Arrow-Hover.jpg");

            menuItem.addEventListener("click", function(e) {

                 var all = new All();

                        self.add(all);

            });

...................... ..................... ..........................

Upvotes: 0

Ali
Ali

Reputation: 835

but.addEventListener('click', function(e){

var newwin=Ti.UI.createWindow({url:'another.js'});
 newwin.open();
});

Its a simple event handler in which we are creating and opening a windows and opening after that.Url is the file to the desired window.

Simple.Cheers!!

Upvotes: 0

TheJDP
TheJDP

Reputation: 126

that's not so hard. Incl. params. First create your other .js file and create a function as follows.

Another .js File:

exports.createNewWindow(params) {
    var window = Ti.UI.createWindow ({
        // ... Your stuff with your params
    });
    return window;
}

Than you can call this function as follows:

First .js File

var window = require("pathToYouAnotherFile.js").createNewWindow({title:"xyz"});
window.open();

If you want you can call the window.open() in the "another.js" file.

Have fun.

Upvotes: 2

Kevin
Kevin

Reputation: 1141

I handled this by raising an event from one JS file to another. Take a look at Ti.App.fireEvent('event',data) to fire the event and Ti.App.addEventListener to receive the event.

Upvotes: 0

Dawson Toth
Dawson Toth

Reputation: 5680

You should learn Alloy. It will help you properly structure your app, as you have asked.

http://projects.appcelerator.com/alloy/docs/Alloy-bootstrap/index.html

Upvotes: 0

Related Questions