exception on exported function
Closed this issue · 11 comments
I've got this controller called property and exported a single function
$.foo = function() {
Ti.API.log('test');
};
and in my index controller
$.myButton.addEventListener('click', function(e){
$.property.foo();
})
On click event, got the following errors :
2012-07-26 01:41:40 -- [WARN ] Exception in event callback. {
2012-07-26 01:41:40 -- [INFO ] line = 95;
2012-07-26 01:41:40 -- [INFO ] message = "'undefined' is not an object (evaluating '$.property.foo')";
2012-07-26 01:41:40 -- [INFO ] name = TypeError;
2012-07-26 01:41:40 -- [INFO ] sourceId = 243267968;
2012-07-26 01:41:40 -- [INFO ] }
If you have required in property in your index controller try removing the $. in front of property.foo().
Controllers are tightly coupled with views right now. That means only controllers that have an associated view will generate code for runtime usage.
What is the purpose of your "property" controller? Perhaps I could better help shape your alloy app if I knew the intent of this controller.
@tonylukasavage my index is a TabGroup View which contains 3 tabs. The first tab has a button that when clicked will open up property controller and I'd like this to be a modal window.
Although, It works when I do the following in my index controller's eventlistener :
$.prpBtn.addEventListener('click', function(e){
var window = Ti.UI.createWindow({
navBarHidden:false,
modal:true,
backgroundColor: 'white' });
window.open();
});
but that seems to defeat Alloy's purpose. Is there a better way to do this ?
I'm on Alloy v0.1.23
cheers
So If I'm understanding correctly, "property" is a separate controller, with an associated view, and you's like to open it programmatically from your index controller? If that's the case...
$.prpBtn.addEventListener('click', function(e){
// getRoot() gets the root UI element of your component, in this case your window
var win = Alloy.getComponent('property').getRoot();
win.open();
});
Also to note, there's markup shortcuts for events. Instead of explicitly writing:
$.prpBtn.addEventListener('click', function(e){
you could do this in markup:
<Button id="prpBtn" onClick="openWindow"/>
and this in the corresponding controller:
function openWindow(e) {
// your code
}
thanks for the reply... but I'm still getting this undefined/exception error :
2012-07-31 22:37:00 -- [WARN ] Exception in event callback. {
2012-07-31 22:37:00 -- [INFO ] line = 8;
2012-07-31 22:37:00 -- [INFO ] message = "'undefined' is not a function (evaluating 'Alloy.getComponent(\"property\").getRoot()')";
2012-07-31 22:37:00 -- [INFO ] name = TypeError;
2012-07-31 22:37:00 -- [INFO ] sourceId = 243091840;
2012-07-31 22:37:00 -- [INFO ] }
Also, I got exception when I used require instead of Alloy.getComponent
other than cheers for the effort on Alloy
You probably need to make sure you are using the latest Alloy to use that method. Be warned though, lot'f of stuff is still changing. Updating could potentially cause other things to not work.
@tonylukasavage yup thanks, Im pretty aware of those stuff... Im on bleeding edge now. Anyway, I may have overlooked some stuff so I'll try to fiddle around. Cheers
This doesn't seem to work on my end, I've provided some details with my development setup. Let me know if you need more details.
I've downloaded Titanium SDK/Studio (never went for upgrade), synced with the bleeding edge and used the 'getController' method but Im still getting this callback exception.
message = "'undefined' is not a function (evaluating 'Alloy.getController(\"property\").getRoot()')";
My setup
- Mac OSX 10.6.8
- Python 2.6.1
- SDK 2.1.1.GA
- Alloy 0.2.0
I would appreciate any help thanks ;)
@rixrix I think you caught us while we were making some changes to the Alloy.getController("name") method. If you like can you can post your view, style, controller code? We should probably be able to figure out what is up quickly.
@mtnlife999 Here's my code
index
/controller/index
$.parentController = Alloy.getController('BaseController');
function preLayout(args) {}
function postLayout(args) {
$.label.on('click',function(e) {
var win = Alloy.getController('property').getRoot();
win.open();
});
$.index.open();
}
/styles/index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000"
}
/views/index.xml
<Alloy>
<TabGroup>
<Tab id="homeTab">
<Window class="container">
<Label id="label">Hello, World</Label>
</Window>
</Tab>
<Tab id="statsTab">
<Window class="container">
<Label>Stats</Label>
</Window>
</Tab>
</TabGroup>
</Alloy>
property
/controller/property.js
$.parentController = Alloy.getController('BaseController');
function preLayout(args) {}
function postLayout(args) {}
/styles/property.tss
".container": {
backgroundColor: "white"
}
/views/property.xml
<Alloy>
<Window>
<View class='container'>
</View>
</Window>
</Alloy>
closing this as the controller syntax has changed since this issue was created.