Button removed with removeChild() gets re-added in it's over state
I have a SimpleButton on the stage, and in the click event for it, I remove it using removeChild()
. When re-adding the button, it gets re-added in it's "over" state, not t开发者_如何学Pythonhe "up" state as expected.
I'm pretty sure it's a bug, so I've filed a JIRA: http://bugs.adobe.com/jira/browse/SDK-31445, my question is now on how to fix it, if anybody's had a similar experience.
What I've tried:
- using
visible = false
instead works, but I'd prefer to remove it off the stage altogether as the game I'm working on can have a lot of popups/screens. - Firing the
mouse_out
event manually - doesn't work, and in any case, themouse_out
event fires as expected (perhaps before resetting to the up state, it makes a check to see if it's added to the stage, finds out it's not, then quits early) - Resetting the stage focus - I thought it was a problem with the stage focus, as you were losing focus when the button was hidden, but resetting it didn't fix it.
- I could temporarily swap the over and up state when it's hidden, but that seems like an ugly fix.
I've been Having this problem as well, removing one button and adding another in response to an Mouse up event on a separate sprite.. IE the mouse isn't over either of the buttons at the time, But when the first button (the one with the problem) was previously removed the mouse was indeed over it so it hadn't received a mouseOut event and retained itself in the over state. Using visibility to work round this which is ok for my needs BUT the alternative answer would be to replace with a new instance of the button before adding it to the Display List.
精彩评论