首页 文章

MouseDown事件未触发

提问于
浏览
0

我在计时器上不断创建数百个动画片段,每个片段都有一个mouseDown事件监听器,它将删除mouseDown上的movieclip . 对于几乎所有的动画片段,mouseDown事件似乎都正确触发,但有时我注意到mouseDown事件不会为动画片段触发(即它没有被删除) .

这是创建movieclip的功能:

public function pickShape():MovieClip {

        //possible shapes
        var shapes:Array = [new triangle(), new rectangle(), new square()]; 

        var randomCol:int = Math.floor(Math.random()*colours.length);

        var randomShape:int = Math.floor(Math.random()*shapes.length);

        var chosenShape:MovieClip = shapes[randomShape];

        //change shape to random colour
        var shapeCol:ColorTransform = chosenShape.transform.colorTransform;
        shapeCol.color = colours[randomCol];
        chosenShape.transform.colorTransform = shapeCol;


        chosenShape.addEventListener(MouseEvent.MOUSE_DOWN, destroyShape); //remove mc

        return chosenShape;
    }

pickShape()是从另一个在timerEvent上调用的函数调用的,在另一个函数中,selectedShape的scaleX,scaleY和rotation被改变 . selectedShape将在EnterFrame中在屏幕上移动,当它在屏幕外时会被删除 .

什么会导致这个?

谢谢你的帮助

1 回答

  • 0

    你的destroyShape函数是这样的:

    function destroyShape(e:MouseEvent):void
    {
    e.currentTarget.parent.removeChild(e.currentTarget);
    }
    

相关问题