2
xtype: 'component',
                        cls: 'headerComponent',
                        id: 'RequirementHeader' + i,
                        itemId: 'requirementHeaderViewID-' + i,
                        html: arrReqTplHeader,
                        constructor: function (config) {
                            var me = this,
                                currentConfig = me.config;
                            me.fireEvent('initialize', me);
                        },
                        initialize: function (obj) {
                            var me = this;
                            me.element.down('img').on('tap', me.imageTap, this, me);                            
                        }, imageTap: function (obj) {
                        alert("it doest reach here");
                        }

I have this component in sencha touch that works fine when I am using it on testing environment, but as soon as I build the project it does not call the initialize function in the build version, Can someone please help me with this. I have tried googling the issue already but of no use.

Darin Kolev
  • 3,401
  • 13
  • 31
  • 46
Nick Div
  • 5,338
  • 12
  • 65
  • 127
  • Does it work when you run "sencha app build testing"? Also, do you hit any errors? It's possible the "img" on which you try to assign the tap listener isn't yet available when that code is executed. – arthurakay Apr 23 '14 at 17:06
  • after building it does work, if I access it without building it works fine. – Nick Div Apr 23 '14 at 17:12
  • sorry after building it does not work – Nick Div Apr 23 '14 at 17:42
  • So what happens when you use "sencha app build testing", does it work? Also, can you provide a sample with this component? We can debug it – Baidaly Apr 26 '14 at 01:50

1 Answers1

1

Don't forget to call the parent method when you override initialize:

initialize: function (obj) {
    var me = this;
    me.callParent(arguments); 
    me.element.down('img').on('tap', me.imageTap, this, me);
}

And I think in this case you don't need the constructor, because initialize is always called.

Darin Kolev
  • 3,401
  • 13
  • 31
  • 46
  • I had found this solution on Google, but this also does not work. Thanks for your answer though, I hope it helps someone else with same issue. Upvoted. – Nick Div Apr 25 '14 at 15:44
  • Any errors? Please post more code, it looks more like scope problem – Darin Kolev Apr 25 '14 at 15:46
  • I dont see any errors on the console and the code also doesnt get stuck anywhere. And I have posted the whole code. the only thing missing from the code is the HTML that has the images. – Nick Div Apr 25 '14 at 15:49
  • look at the examples here: http://www.sencha.com/forum/showthread.php?178028-Dispatching-an-event-on-image-click-in-Sencha-Touch-2 Maybe on initialize is too early to set a handler for the event – Darin Kolev Apr 25 '14 at 15:54
  • thats what I did ultimately, added listeners and inside painted I captured the tap event using delegate:.imgClass it works fine for me but that is a very hard coded solution, now I have to keep track of the className always, it cripples the reusability – Nick Div Apr 25 '14 at 15:57
  • or maybe run callParent() at the beginning of initialize (edited in the answer). It is really hard for me to make suggestions without the running code. – Darin Kolev Apr 25 '14 at 16:02
  • I tried that as well and I also understand that you need the code to run and test but the whole code is more than 2000 lines. Its ok for now may be I will just use the hard coded solution and I will soon create a template by removing unecessasry code and sending you the link that will contain code that you can run and reproduce the error. But still if you want you can just add some random HTML div with an image inside it. – Nick Div Apr 25 '14 at 16:43