titaniumappceleratortitanium-mobileappcelerator-titaniumappcelerator-mobile

require statement not working properly with Titanium SDK 8.0.0.GA


I have a classic titanium app, for some reason the require statement is not working properly

For example:

require("views/Player");

The required file is supposed to modify a global variable, but after requiring it the global variable is not modified.

The weirdest thing that it works fine when compiling against Ti SDK 7.4.2.GA and doesn't work when compiling against any newer version.

Can anyone explain this?


Solution

  • Okay, it turned out that prior to SDK 7.5.0, the app.js would assign any top-level variables to the global object. But not after that.

    To fix it, you should declare global variables like this

    global.labelText = 'Titanium Doesn't Rock!';
    

    instead of this

    var labelText = 'Titanium Doesn't Rock!';
    

    More info here: https://docs.appcelerator.com/platform/latest/#!/guide/Titanium_SDK_7.5.0_Functionality_Update