Hi guys, I have a little problem that is making me crazy... I create my little module but when I try to initialize it at the application start nothing happen... btw it works fine if I call the function by clic on button.
Here is the module:
var width = Ti.Platform.displayCaps.platformWidth - 40; //Dimensione riquadri var cellWidth = width*0.33; var cellHeight = width*0.33; //Distanze var xSpacer = 10; var ySpacer = 10; //Griglia var xGrid = 3; var yGrid = 5; //Colori var colorSet = ["#D44646","#46D463","#46D4BE","#C2D446","#D446D5","#4575D5","#E39127","#879181","#E291D4"]; function setGalleryGrid(imageAmount) { if(imageAmount > 15) { yGrid = Math.ceil(imageAmount/xGrid); } //inizializza var tableData = []; var cellIndex = 0; var colorSetIndex = 0; for (var y=0; y<yGrid; y++){ var thisRow = Ti.UI.createTableViewRow({ className: "grid", layout: "horizontal", height: cellHeight+(2*ySpacer), backgroundSelectedColor:"red" }); for (var x=0; x<xGrid; x++){ var thisView = Ti.UI.createImageView({ objName:"grid-view", objIndex:cellIndex.toString(), backgroundColor: colorSet[colorSetIndex], //image: "/images/photo.png", borderRadius:10, left: ySpacer, height: cellHeight, width: cellWidth }); var thisLabel = Ti.UI.createLabel({ color:"white", font:{fontSize:48,fontWeight:'bold'}, text:cellIndex.toString(), touchEnabled:false }); thisView.add(thisLabel); thisRow.add(thisView); cellIndex++; colorSetIndex++; if( colorSetIndex === colorSet.length ){ colorSetIndex = 0; } } tableData.push(thisRow); } return tableData; } module.exports = setGalleryGrid;main file
function setGrid(pics){ if(typeof pics == 'undefined') { pics = 0; } var setGalleryGrid = require('JS/onGalleryGrid'); $.galleryGrid.data = new setGalleryGrid(pics); }; function inizializzaGallery(){ var width = Ti.Platform.displayCaps.platformWidth; var height = 0.95*width; setGrid(); // <<<--- IT DOESN'T WORK }; inizializzaGallery(); // CALL ON APPLICATION START $.settingButton.addEventListener('click',function(e){ setGrid(); // <<<--- IT WORKS });Why I can't initialize my module calling the function setGrid() on application start? Where am I wrong?
Regards, Matteo