Question

I cant seem to access the viewPort property of FotoAlbum from any other module nor can I run any function I try to add to FotoAlbum. Im completely new to CommonJS so it might be an easy fix, but I don't see it right now.

function FotoAlbum(app)
{
    var self = Ti.UI.createWindow(
    {
        title : 'Fotoalbum',
        backgroundColor : '#fff',
        layout : 'vertical',
        height : 'auto',
        width : 'auto'
    });

    this.t=3;

    self.add(app.Navigation.getNavigationBar(app));

    this.viewPort = Ti.UI.createView(
    {
        top : '0dp',
        left : '0dp',
        width : '100%',
        height : 'auto',
        backgroundColor : 'white'
    });

    var label = Ti.UI.createLabel(
    {
        text : 'Foto album'
    });
    this.viewPort.add(label);
    self.add(this.viewPort);

    return self;
}
module.exports = FotoAlbum;
Was it helpful?

Solution

this refers to the context of the function FotoAlbum, but you are using this function to create and return a view, this is why you cant access the functions context, and therefore the attributes attached to it.

So to make this work, just attach your methods and attributes to the View itself like this:

function FotoAlbum(app) {
    var self = Ti.UI.createWindow();
    // Attach to the view
    self.t=3;
    self.add(app.Navigation.getNavigationBar(app));
    self.viewPort = Ti.UI.createView();

    var label = Ti.UI.createLabel({
        text : 'Foto album'
    });
    self.viewPort.add(label);
    self.add(self.viewPort);

    return self;
}
module.exports = FotoAlbum;

EDIT: Forgot to mention, don't attach objects to the view and then change that object's attributes, that won't work because of how javascript proxies function in Titanium.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top