Titanium Community Questions & Answer Archive

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

Working code can't see vars after moving into an include file

Hey, got a big chunk of code that works great. moved it to an include file and added Ti.include('filename.js') and started getting "can't find variable x' errors.

The include line is placed in the exact same spot where the orig code was so it should look exactly the same at run-time.

Probably something staring me in the face!


— asked August 4th 2010 by Kelly Redd
  • include
  • iphone
  • Have the same issue, using 1.4.x. Working on a big app and need to split code into modules, but because of this will have to keep all code in the same file.

    — commented August 27th 2010 by Adam Renklint
  • I had same problem. it was about file encoding. Originaly files were encoded in utf-8, but somehow they were converted to macroman.
    Editing files to set encoding to uf8 should solve it.

    — commented January 27th 2011 by Ignasi Artigas

5 Answers

  • I have had the same issue and as a result I have not migrated to 1.4.X

    — answered August 4th 2010 by Steve Clarke
  • Does Titanium.include work? As opposed to Ti.include?

    — answered August 4th 2010 by Alan Bourke
    1 Comment
    • Ti.include works in that it does include the file, it just doesn't have access to the variables once its included.

      — commented August 5th 2010 by Kelly Redd
  • Bump.

    — answered September 9th 2010 by Kelly Redd
  • I use an included file to set colors and common styles. I put the include statement in my app.js file and the variables are all available in my other files. See the "Global Context and Threading" section at http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI-module

    I'm using Titanium.include('styles.js'); to include the file. Then, I can use its variables throughout the rest of my script. Statements like the following also work for me to include a file and open the window it defines:

    Titanium.include('profilepicker.js'); // defines pickwin window

    See the "Passing Data" section at http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object for info on passing data between windows/files.

    I'm using the newest Titanium developer (title bar says 1.2.1 but I downloaded it last week) with the nightly builds of the 1.4.1 api (1.4.0 were very buggy).


    — answered September 9th 2010 by Tim Poulsen
  • The issue has been resolved for both platforms since this thread was started. See TIMOB-1662.


    — answered May 16th 2011 by Paul Dowsett
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.