Titanium Mobile Global Variables

615 views
Skip to first unread message

Sam Doyle

unread,
Mar 2, 2011, 3:43:52 PM3/2/11
to appcelerat...@googlegroups.com
Hi,

I'm not sure if this list supports Titanium Mobile API, my apologies if not.

I'm trying to access what I want to be a global variable:

I have my app.js set up with some variables and functions. I then load my home window as follows:

[code]
var home = Ti.UI.createWindow({ url : 'main_windows/home.js'});
home.open();
[/code]
from home.js I'm trying to access a function but titanium console gives me the following error:

expressionBeginOffset = 476;
expressionCaretOffset = 487;
expressionEndOffset = 487;
line = 29;
message = "Can't find variable: openResults";
name = ReferenceError;
sourceId = 237465792;
sourceURL = "file://localhost/Users/sam/Dev/iPhone%20Apps/SEO%20App/Resources/main_windows/home.js";
}

For reference openResults is actually a function, not a variable.

Any help will be taken gladly.

Sam

dan tamas

unread,
Mar 2, 2011, 3:51:09 PM3/2/11
to Appcelerator Titanium
Each window declared with an url runs in it's own scope, so you will
not be able to do it this way.
The best way is to pass to that window the vars in the constuctor

in app.js


--------------
var blah = 'something';
var home = Ti.UI.createWindow({ url : 'main_windows/home.js', my_var:
blah });
--------------

and din home.js

--------------
var win = Titanium.UI.currentWindow
alert(win.my_var);
--------------

Sam Doyle

unread,
Mar 2, 2011, 5:05:20 PM3/2/11
to appcelerat...@googlegroups.com
Thanks for a fast response.

______________
Sam Doyle
@sam_doyle

> --
> You received this message because you are subscribed to the Google Groups "Appcelerator Titanium" group.
> To post to this group, send email to appcelerat...@googlegroups.com.
> To unsubscribe from this group, send email to appcelerator-tit...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/appcelerator-titanium?hl=en.
>

Reply all
Reply to author
Forward
0 new messages