Display object losing the addEventListener function

In my storyboard createScene function I am adding a series of nested display groups, at the heart of which is a group of images. Once the enterScene function is called I can no longer add event listener functions (in this case for the 'tap' event) to the images because the addEventListener function throws an exception and appears to be nil as a value of the object table.

Is this a known issue, are there caveats to using the storyboard api and display groups and event handlers or should I post my code? (It is quite long, has many related files and I would most likely end up posting my entire app, which I'm loathed to do right now.)

Thanks,

Matt.

Right, illness and lack of sleep are the enemy of the coder, so here's the solution. It's not actually a storyboard problem but a function reference issue...

The code follows and you don't need to be able to run it, because I was assuming that the function 'addEventListener' was suddenly no longer available on the display object (a png) but in fact it was the function I was referencing as the event handler which could not be asserted (which means 'found' by the runtime).

The broken version was this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
scene.levelselect = function( event )
        print( event )
end
 
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
        local group = self.view
        
        local sectiongroup = group[ storyboard.selectedsection ]
        for i=1, sectiongroup.numChildren do
                local levelgroup = sectiongroup[i]
                levelgroup.icon:addEventListener( "tap", scene.selectlevel )
        end
end

One problem left remaining with this implementation is that the parameter argument received by the levelselect function is always nil.

Could anyone tell me why please?

My only solution at present is to make the function local and not a member of the scene object, which I really don't feel is OO enough for my tastes.

Matt.

views:1818 update:2012/2/8 8:46:10
corona forums © 2003-2011