How to hide an animated sprite after one loop of animation?

Hi, I am creating an animated widget button. When I press the widget button it will show the animated button. When I release the widget it will direct me to another scene. 

Problem: 

When I release the button and it directs me to another scene the button - animated sprite Visibility is shown in the new scene. I want the button-animated sprite to disappear when it changes to another scene.

For the animated button I use sprite animation.

local button1Press = function( event ) --show animation when is pressed local buttonBye2 = graphics.newImageSheet( "images/button\_animation\_small.png", { width=108, height=108, numFrames=20, border = 0 } ) -- play 8 frames every 1000 ms --this bye\_Animation object is not local local bye\_Animation = display.newSprite( buttonBye2, { name="play", start=11, count=20, time=1500, loopCount = 1 } ) --properties of the button. The size and the position. bye\_Animation.x = 250; bye\_Animation.y = 400 bye\_Animation:play() screenGroup:insert(button1Press) return true end

For directing me to another scene after the button is release I use storyboard. 

 local function button1Release( event ) if event.phase == "ended" then storyboard.gotoScene( "scene1", "fade", 800 ) return true end

I attached my code file. Thank you for your time. 

Most likely it’s because your bye_Animation sprite isn’t being added to your sceneGroup so it just becomes an orphaned object.

Thank you very much it works now! 

Just remove the the button when the frame of the animation is at the last frame. [lua]

– runtime enter frame function, 

local function enterFrameBtn(event)

if buttonBye2.frame == 20 then

buttonBye2:delete()

buttonBye2 = nil

Runtime:removeEventListener( “enterFrame”, enterFrameBtn )

end

end

local function button1Release( event )
if event.phase == “ended” then

 Runtime:addEventListener( “enterFrame”, enterFrameBtn )

storyboard.gotoScene( “scene1”, “fade”, 800 )
return true

end

       

[/lua]

This is how I do when I have sprites that explode. I wait for last frame then remove. 

Thank you very much!

I have another question related to this one:  

http://forums.coronalabs.com/topic/37207-hide-widget-buttons-defaultfile-in-storyboard/

Most likely it’s because your bye_Animation sprite isn’t being added to your sceneGroup so it just becomes an orphaned object.

Thank you very much it works now! 

Just remove the the button when the frame of the animation is at the last frame. [lua]

– runtime enter frame function, 

local function enterFrameBtn(event)

if buttonBye2.frame == 20 then

buttonBye2:delete()

buttonBye2 = nil

Runtime:removeEventListener( “enterFrame”, enterFrameBtn )

end

end

local function button1Release( event )
if event.phase == “ended” then

 Runtime:addEventListener( “enterFrame”, enterFrameBtn )

storyboard.gotoScene( “scene1”, “fade”, 800 )
return true

end

       

[/lua]

This is how I do when I have sprites that explode. I wait for last frame then remove. 

Thank you very much!

I have another question related to this one:  

http://forums.coronalabs.com/topic/37207-hide-widget-buttons-defaultfile-in-storyboard/

alternative variant

local function spriteListener(event)

            if bye_Animation.frame == 20 then

                bye_Animation.alpha = 0.01 --hides 

            end

end

bye_Animation:addEventListener(“sprite”, spriteListener)

alternative variant

local function spriteListener(event)

            if bye_Animation.frame == 20 then

                bye_Animation.alpha = 0.01 --hides 

            end

end

bye_Animation:addEventListener(“sprite”, spriteListener)