Hi guys, I have a problem with my button to open Titanium.Media.openPhotoGallery() and Ti.Media.showCamera().
When I put this code in my index.js is all right:
var popoverView; var arrowDirection; $.sx.addEventListener('click',function(e){ Titanium.Media.openPhotoGallery({ success:function(event) { var isAvatar = true; var image = event.media; if(typeof imageAmount == 'undefined') { isAvatar = false; } // Carica immagine su server var xhr = Titanium.Network.createHTTPClient(); xhr.onerror = function(e) { Ti.API.info('IN ERROR ' + e.error); Ti.App.fireEvent('AggiornaGallery'); }; xhr.onload = function() { Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState); Ti.App.fireEvent('AggiornaGallery'); //alert(this.responseText); }; xhr.onsendstream = function(e) { Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress); }; xhr.open('POST',linkdb+'upload.php'); var params = { file:image, avatar:isAvatar, id: myaccount[0].id, username: myaccount[0].username, continent: myaccount[0].continent, country: myaccount[0].country, city: myaccount[0].city }; xhr.send(params); }, cancel:function(){}, error:function(error){}, allowEditing:true, popoverView:popoverView, arrowDirection:arrowDirection, mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO], }); });
but if I try to to export it in a external js to include in my index it never oper my gallery or camera at the first click but I have to click on my button 2 times.... WHY?????
index.js
$.sx.addEventListener('click', _openGallery); function _openGallery(){ var openGallery = require('/JS/onGallery'); var OpenGallery = new openGallery($.imageView); }onGallery.js
var popoverView; var arrowDirection; function openGallery(imageView) { Titanium.Media.openPhotoGallery({ success:function(event) { var isAvatar = true; var image = event.media; if(typeof imageAmount == 'undefined') { isAvatar = false; } // Carica immagine su server var xhr = Titanium.Network.createHTTPClient(); xhr.onerror = function(e) { Ti.API.info('IN ERROR ' + e.error); Ti.App.fireEvent('AggiornaGallery'); }; xhr.onload = function() { Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState); Ti.App.fireEvent('AggiornaGallery'); //alert(this.responseText); }; xhr.onsendstream = function(e) { Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress); }; xhr.open('POST',linkdb+'upload.php'); var params = { file:image, avatar:isAvatar, id: myaccount[0].id, username: myaccount[0].username, continent: myaccount[0].continent, country: myaccount[0].country, city: myaccount[0].city }; xhr.send(params); }, cancel:function(){}, error:function(error){}, allowEditing:true, popoverView:popoverView, arrowDirection:arrowDirection, mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO], }); }; module.exports = openGallery;Where am I wrong???
Regards, Matteo