Rajesh Vishnani
Rajesh Vishnani

Reputation: 93

load js on image click titanium

i am new to titanium apps, i want to load a js on image click but i get 'uncaught typeerror cannot call method 'open' of undefined' error.

app.js

Ti.include("/core/index.js");

index.js

var win = Ti.UI.createWindow({
title: 'MapApp',
layout: 'vertical',
backgroundColor: '#ffffff'
});

var home=Ti.UI.createImageView({
  image:'home.png',
  height : 130,
  width : 130,  
});
var about=Ti.UI.createImageView({
  image:'about.png',
  height : 130,
  width : 130
});
var rss=Ti.UI.createImageView({
  image:'rss.png',
  height : 130,
  width : 130
});
var contact=Ti.UI.createImageView({
  image:'contact.png',
  height : 130,
  width : 130
});

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

var newWin = Ti.UI.createWindow({
url : 'map.js',
title : 'title',
tabBarHidden : true,
barColor : '#000000',                
    });
    newWin.open({
animation:true
});  
});

win.add(home);
win.add(about);
win.add(rss);
win.add(contact);
win.open();

map.js

var globals = require("globals");

(function(){
    var config = require("Config"),
        AppWindow, LocationManager, locationsHandler;

    globals.theme = require("../themes/" + config.theme);
    LocationManager = require("LocationManager");

    Titanium.UI.backgroundColor = globals.theme.Global.backgroundColor;

    locationsHandler = function(e){
        AppWindow = require("../ui/AppWindow").create();
        AppWindow.open();
        Ti.App.removeEventListener(
            LocationManager.events.LOCATIONS_READY,
            locationsHandler
        );
    };

    Ti.App.addEventListener(
        LocationManager.events.LOCATIONS_READY,
        locationsHandler
    );

    // Load locations
    LocationManager.load(); 
})();

i searched a lot, but did not get any response, is there any problem with the code in map.js as i replaced that code from app.js from purchased theme.

Upvotes: 0

Views: 91

Answers (1)

Ankush Sharma
Ankush Sharma

Reputation: 933

You can use the Event fire and event listener for this purpose and in my sense it will be the wise thing to do also. Once you have registered an even, fire it when the image is clicked. When the event is fired, the event you registered will hear it and will load your concern js and then you can take it from there.

Here is the link that might help you to get it going. You may fire and register both the event in app.'s or in any other js you are using. Once you get it right, the other thing will be easy to do.

Upvotes: 1

Related Questions