user3624383
user3624383

Reputation: 97

Appcelerator Alloy project working with Functions or Classes

I made an Alloy project trying to understand how to work with separate JS files.

So far i tried to make Functions and Classes with no success.

Here's an example of a Class that i tried to make.

index.js

var Label = require("test");
label = new Label();

$.index.add(label);
$.index.open();

test.js

//Create Function

function Label() {  

// Create label
  var label = Ti.UI.createLabel({
    text:"qweqwe"
});

// Return label
return label;
}

module.exports = Label;

When i try to compile i get this error

enter image description here

Can you please demonstrate the proper structure of a Function or Class that i can later use from an other js file using module.exports or exports.

Upvotes: 0

Views: 77

Answers (2)

Fokke Zandbergen
Fokke Zandbergen

Reputation: 3866

Please read the Alloy QuickStart about views, requiring controllers and widgets. what you are doing is mixing classic and alloy with no (clear) reason, which is not considere best practice.

Upvotes: 1

Suraj kochale
Suraj kochale

Reputation: 973

The error shows that, the file path of test module is wrong. Add your test.js file in lib folder as shown below, and try

enter image description here

it works for me. also refer CommonJs module in Titanium

Upvotes: 2

Related Questions