Greetings,
I have been working on a custom namespace in appcelerator but have run into a problem updating global namespace variables from within certain Titanium objects.
I have a wrapper called “myObj“, and inside of myObj is another object called “globals” which contains variables that are set and used throughout the namespace.
myObj.globals = {
userBalance: null,
userAuthenticated: false,
deviceGeoActive: false
}
So I’ve created a custom wrapper for the geolocation module and inside of that wrapper is the standard Ti.Geolocation.getCurrentPosition(e) function and some custom stuff to be used with the app.
Inside of the Ti.Geolocation.getCurrent…(e) I check to see if location service is available on the device and has been authorized for the app. Then I want to update the deviceGeoActive object property in myObj.
Ti.Geolocation.getCurrent...(e){
if (e.success){
myObj.globals.deviceGeoActive = true
}
}
This way I’ll be able to check if the device is Geo enabled anywhere, anytime.
Why I believe it’s failing (and this is a guess, I’m fairly new at javascipt) is because Ti is outside of the myObj namespace and therefore cant access it in this way.
Can anybody point me in the proper direction?
Thanks,
Josey
Thanks @Khez for helping get me to this point!
Titanium Appcelerator doesn’t work inside of the window namespace but your suggestion did make me think to add myObj to the global Ti (or Titanium) namespace.
So in the beginning I had this:
But myObj was being ignored by Ti.
To add it to the global Titanium namespace I modified it like so:
This way any calls to myObj remain don’t have to be changed to reference Ti.
This means that myObj is now a child of the parent (global) Ti namespace.
Thanks again Khez