AddChild removeChild mouse click
I've been experimenting with addChild removeChild but the respective movie clips don't initiate when called from their assinged button they only begin to funtion if the oposite button is clicked first.
Example click button1 nothing, click button2 nothing, click button1 again and it works.
I suspect it's something to do with the removeChild function, but I'm not at all sure why it's not initiating on first click.
this.buttonAddRec.addEventListener("click", addPurpleRect.bind(this));
this.buttonAdd.addEventListener("click", myRectangle.bind(this));
function addPurpleRect()
{
if (!addPurpleRect)
{
addPurpleRect = new lib.RectangleTwo();
addPurpleRect.x = 250;
addPurpleRect.y = 150;
this.addChild(addPurpleRect);
}
else (myRectangle)
{
this.removeChild(myRectangle);
myRectangle = null;
}
}
function myRectangle(e)
{
if (!myRectangle) {
myRectangle = new lib.Rectangle();
myRectangle.x = 150;
myRectangle.y = 150;
this.addChild(myRectangle);
}
else (addPurpleRect)
{
this.removeChild(addPurpleRect);
addPurpleRect = null;
}
}