0

I am new in Titanium 3.x and I have made my first simple Titanium project.It just opens new window using another JS file. I write code in index.js like below. and I create new js file "createnew.js" in app/controllers/.

//////////////////////////////////////
button.addEventListener('click',function(e)
{
    var childWindow = Ti.UI.createWindow({
        url: 'createnew.js'
    });
    childWindow.open();

});
///////////////////////////////////////
// createnew.js
///////////////////////////////////////


        var self = Ti.UI.createWindow();

        var overview = Ti.UI.createView({
            width: Ti.UI.FILL,
            height: Ti.UI.FILL,
            backgroundColor: 'yellow'

        });
    self.add(overview);

    self.open();

When run app, if I click button, the red error window appears in simulator , says that cannot open createnew.js file, cannot find such file or directory.

How can I solve this problem?

My aim is to make every page of the Mobile app as different Js file, and when It goes to the page, I can just use calling createWindow() to load Js file. Please help me .

turtle
  • 1,619
  • 1
  • 14
  • 30
  • use `var self = Ti.UI.currentWindow`, and why are you again opening window `self.open();` you have had open window earlier in `childWindow.open();` – Swanand Jul 14 '14 at 11:12
  • have a look at the following links 1. http://stackoverflow.com/questions/17849977/how-to-load-another-js-file-on-a-button-click-in-titanium, 2. http://stackoverflow.com/questions/14949025/titanium-mobile-cant-navigate-between-pages/14949895#14949895. Try to use the method two, commonJS, if you are planning to use classic style – Anand Jul 14 '14 at 11:27

1 Answers1

1

You wrote :

I create new js file "createnew.js" in app/controllers/.

So it seems that you are following allow framework of Titanium. But with the coding style it seems you are using classic Titanium structure.

Please do not get confused and follow the Titanium coding style at following links :

turtle
  • 1,619
  • 1
  • 14
  • 30
  • I am new in Titanium. So I'd like you teach me. Which one is simple and powerfull for new develper? Classic or Alloy? – user3836230 Jul 14 '14 at 11:07
  • In my opinion Alloy has a proper mvc structure and much cleaner than classic , so you should go with Alloy. – turtle Jul 14 '14 at 11:09
  • You can follow these links for help : [Appcelerator Titanium Alloy](http://www.slideshare.net/karthi-anubavam/appcelerator-titanium-alloy) and [Titanium Alloy (MVC) development](http://stackoverflow.com/questions/14116071/i-need-help-understanding-titanium-alloy-mvc-development) – turtle Jul 14 '14 at 11:17
  • 1
    I also agree with sumit, MVC approach will be easy to understand rather than going behind classic. – Dragon Jul 14 '14 at 11:53