View Full Version : addChild
fs_tigre
February 11th, 2008, 08:47 PM
I am adding a child when a button is clicked, everything is working fine but it keeps adding a new child every time the button is clicked. How can I prevent this if I only want one child on the stage?
Thanks,
fs_tigre
Escape-Artist
February 11th, 2008, 10:00 PM
You need to remove the event listener once your child as been added.
So right after you add your child, write:
myButton.removeEventListener( MouseEvent.MOUSE_DOWN, nameOfYourFunction );You need to replace "myButton" by the instance name of your button and "nameOfYourFunction " by the name of the function that is called when you click on the button. Also I used MouseEvent.MOUSE_DOWN but you might have used something else like: MouseEvent.CLICK....
Anyway to make simple, copy the line where you add the event listener to your button, and replace addEventListener by removeEventListener....
Let me know if you have troubles.
fs_tigre
February 12th, 2008, 07:26 AM
Wow, I am impressed about the quick response. Thank you Escape-Artist this is a big help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.