0

目前,如果您单击您创建的框,它将删除该框,但会立即创建另一个框。我想在舞台上单击以创建一个框,然后单击该框以删除该框-仅此而已。

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);

    }

}

编辑 - 通过制作单独的背景影片剪辑并将其用作可点击对象来修复它

4

1 回答 1

0

只有一个不同的功能是在 mousedown 上,第二个功能在 mouseClick 上。我觉得你的情况都是一样的......

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");

        }   


    }

}
于 2013-10-13T22:44:12.413 回答