Scope Problem --Help???
my data.json
{
"name":"test"
}
my app.js
Ti.include('brain.js');
var win=Ti.UI.createWindow({
title:'win1'
});
Ti.APi.info("win1 "+json.name);
var btn1=Ti.UI.createButton({title:'click me'});
btn1.addEventListener('click',function(e){
var win1=Ti.UI.createWindow({
title:'win2'
url:'win2.js'
});
win1.open();
});
my brain.js
var json;
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'data.json');
if(file.exists())
{
json=JSON.parse(file.read().text);
Ti.API.info('json object retrived'+json);
}
now in win2.js when i just use a info()
//win2.js
Ti.include('lib.js');
Ti.API.info("Win2 "+json.name);
i can access the json.name, but if i add any kind on UI to the win2 the app exists
var b2=Ti.UI.createButtn({
title:'click me'
});
b2.addEventListener('click',function(e){
var win3=Ti.UI.createWindow({
title:'child 3',
url:'win3.js'
});
win3.open();
});
Ti.UI.currentWindow.add(b2)
can somebody help me on this issue and in another project of mine this scope is killing … i get an object undefined exception….