Question

Problem: Trying out a simple demo for a custom tabgroup in Titanium Alloy. However, the compiler keeps failing with the message Could not find module: common. What I thought would be a straightforward test is anything but.

  • Titanium SDK: 3.1.3.GA
  • OS: iOS 7.x

controllers/index.js

var common = require('common');

function tabGroupClicked(e) {
    common.tabGroupClicked(e);
}

Alloy.Globals.parent = $;
Alloy.Globals.tabGroup = $.tabGroup;
Alloy.Globals.selectedTab = $.tab1;

$.index.open();

controllers/common.js

exports.tabGroupClicked = function(e){
    if (Alloy.Globals.selectedTab !== e.source){

      // reset the selected tab
        Alloy.Globals.previousTab = Alloy.Globals.selectedTab;
        Alloy.Globals.selectedTab = e.source;

        // change the selected flag
        Alloy.Globals.previousTab.selected = false;
        Alloy.Globals.selectedTab.selected = true;

        // change the background image
        Alloy.Globals.previousTab.backgroundImage = Alloy.Globals.previousTab.disabledImage;    
        Alloy.Globals.selectedTab.backgroundImage = Alloy.Globals.selectedTab.selectedImage;

        // swapping the zindexes of the childTabs
        Alloy.Globals.parent.getView(Alloy.Globals.previousTab.childTab).getView().zIndex=2;
        Alloy.Globals.parent.getView(Alloy.Globals.selectedTab.childTab).getView().zIndex=3;
    }
};

index.xml

<Alloy>

        <Window id="index" class="container">

                <View id="tabGroupWindow" zIndex="0" class="container">
                    <Require src="tabThreeView" id="tabThreeView"/>
                    <Require src="tabTwoView" id="tabTwoView"/>
                    <Require src="tabOneView" id="tabOneView" />
                </View>

                <!-- Custom tab group -->
                <View id="tabGroup">        
                    <View id="tab1" onClick="tabGroupClicked"></View>
                    <View id="tab2" onClick="tabGroupClicked"></View>
                    <View id="tab3" onClick="tabGroupClicked"></View>
                </View>

            </Window>
</Alloy>

Can anyone see anything that I'm obviously overlooking? I've cleaned the project, restarted Studio, scoured forums for any reference to this issue. Not finding a reference usually means I forgot some basic detail.

Your help is appreciated.

Was it helpful?

Solution

To use the require function, you have to create a service. So the common.js module as you nammed it, has to be under this folder : app/lib. If it's not in the lib folder, it will not be recognized, and it will not be required. You can find more help in this page.

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