Titanium Community Questions & Answer Archive

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

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….

— asked November 1st 2010 by Satta Ravi
  • android
  • exception
  • iphone
  • object
  • scope
  • undefined
1 Comment
  • The most assured way you have for someone to answer your coding questions is to paste a complete working script, enabling people to paste it quickly into their own environment. Create a gist (or, one for each of your scripts), and I will take a look.

    — commented November 5th 2010 by Paul Dowsett

0 Answers

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.