assertion failed! when trying to add an event listener to a spriteSheetInstance

I have code which plays a spritesheet animation one time.

When it is finished playing, I would like it to loop the last 20 frames, but skip the first 20.

I tried to add an event listener onto the spriteInstance like this:

mySpriteInstance:addEventListener(“sprite”, spriteEvent)
–FYI this instance is inside of another event listener

so that when the event phase is == end, I could do something like this:

sprite.add(sameSpriteSet, “EndLoop”, 11,31,20,0)

The problem is that when I add the event listener, I get the error below (caused when it reaches the addEventListener line)

Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
…ocuments/main.lua:110: in function <…ocuments studio workspace>
?: in function <?:214>

Is there a better way to do this? [import]uid: 4438 topic_id: 4140 reply_id: 304140[/import] </…ocuments>

Could be a problem with your code. Need to see some to debug. [import]uid: 11024 topic_id: 4140 reply_id: 12825[/import]

Here is the function that errors. This function is an event listener on another spriteSheetInstance

local function pullChuteEvent(pEvent)

–media.playEventSound( boingSound )

–slow the sky now that the chute is open
skySpeed = .3

–modify the could speed
randCloudSpeed = math.random( 3000, 5000 )

local chuteSpriteSheetCoordinates = require(“chute”).getSpriteSheetData()
local chuteSpriteSheet = sprite.newSpriteSheetFromData(“chute.png”, chuteSpriteSheetCoordinates)
local chuteSpriteSet = sprite.newSpriteSet(chuteSpriteSheet, 1,32)-- sprite.newSpriteSet(spriteSheet, startFrame, frameCount)

–animate the chute opening
currentDudeXPos = dudeSpriteInstance.x
currentDudeYPos = dudeSpriteInstance.y
dudeSpriteInstance:removeSelf()

sprite.add(chuteSpriteSet, “chute”, 1,32,32,1) --sprite.add( spriteSet, “startFlying”, startFrame, frameCount, time, [loopCount])
local chuteSpriteInstance = sprite.newSprite(chuteSpriteSet)
chuteSpriteInstance:setReferencePoint(display.CenterReferencePoint)
chuteSpriteInstance.x = currentDudeXPos
chuteSpriteInstance.y = currentDudeYPos
chuteSpriteInstance:prepare(“chute”)
chuteSpriteInstance:play()

print(pEvent.phase)
chuteSpriteInstance:addEventListener(“sprite”, spriteEvent)

transition.to(chuteSpriteInstance,{time=2000,y=170})
physics.addBody( chuteSpriteInstance, “dynamic”, { density=2.0,friction=0.0 } )

end [import]uid: 4438 topic_id: 4140 reply_id: 12826[/import]

Is “sprite” something you can look for?

Aren’t “end”, “loop”, or “next” the only options? [import]uid: 11024 topic_id: 4140 reply_id: 12827[/import]

The issue isn’t that I can’t find the event phase and see if it’s == “end”

The issue is that when I add the eventListener to my spriteInstance, I get the error. When I comment out the addEventListener line, it all works as expected.

I’m looking for the end of an animation by adding the event handler to the spriteInstance.

I’m basically trying to do the same thing that’s done in the sample that zwoptex provides (from here http://blog.anscamobile.com/2010/10/zwoptex-sprite-animation-in-corona/)

[import]uid: 4438 topic_id: 4140 reply_id: 12835[/import]

Does spriteEvent (code) appear before or after this? [import]uid: 11024 topic_id: 4140 reply_id: 12836[/import]

You ROCK!! I didn’t even notice that… That’s exactly what it was. THANK YOU, THANK YOU, THANK YOU!!!

[import]uid: 4438 topic_id: 4140 reply_id: 12838[/import]

I’m not smart enough to know. Does the code need to be before or after to make this work? [import]uid: 28218 topic_id: 4140 reply_id: 22525[/import]