0

Currently, if you click the box you made, it will remove that one but instantly create another one. I want a click on the stage to create a box and a click on the box to remove that box - that is all.

import flash.display.MovieClip;
import flash.events.*;



public class testcatnab extends MovieClip
{

    public static var boxCount:int = 0;
    var box = new Box();



    public function testcatnab()
    {
        stage.addEventListener(MouseEvent.CLICK, clickOnStage);
        box.addEventListener(MouseEvent.CLICK, clickOnBox);

    }



    function clickOnStage(e:MouseEvent)
    {

        box.x = mouseX;
        box.y = mouseY;
        addChild(box);

        boxCount++;

        trace(boxCount);

    }



    function clickOnBox(e:MouseEvent)
    {
        boxCount--;
        removeChild(box);

        trace(boxCount);

    }

}

EDIT - fixed it by making a separate background movieclip and using that as the clickable object

  • 1
    You need to stop the click event propagating any further once clickOnBox() has been called... see http://stackoverflow.com/questions/7802601/event-bubbling-and-stop-propagation – Richard Inglis Oct 12 '13 at 09:37

1 Answers1

0

there is only one different one function is on mousedown and second on mouseClick. I thin practicaly both of the in your situation is same...

package  {

    import flash.display.MovieClip;
    import flash.events.*;


    public class Main extends MovieClip {

        private var boxCount:Number = 0;
        private var box:MovieClip;

        public function Main() 
        {
            box = new Box();
            stage.addEventListener(MouseEvent.CLICK, clickOnStage);
            box.addEventListener(MouseEvent.MOUSE_DOWN, clickOnBox);
        }


         function clickOnStage(e:MouseEvent)
        {
            if (boxCount % 2 == 1)
            {
                return;
            }

            box.x = mouseX;
            box.y = mouseY;
            addChild(box);
            boxCount++;
            trace("stage")
        }


      function clickOnBox(e:MouseEvent)
        {
            if (boxCount % 2 == 0)
            {
                return;
            }
            boxCount++;
            removeChild(box);
            trace("box");

        }   


    }

}
oto lolua
  • 499
  • 4
  • 16