形状上的鼠标单击侦听器在actionscript 3.0中不起作用

时间:2013-07-18 12:34:19

标签: actionscript click mouse

你能帮我解决这个问题: 我创建了形状,并使用相同的侦听器函数在它们上面放置了鼠标单击侦听器,但该函数未被调用。

   shape:Shape = new Shape
   shape.graphics.beginFill(color); 
   shape.graphics.drawRoundRect(rx, ry, cWidth, cHeigth, ellipseHeight, ellipseHeight);
   shape.graphics.endFill();
   shape.addEventListener(MouseEvent.CLICK, onMouseClick);
   areaSprite.addChild(shape);


   private function onMouseClick(ev:MouseEvent):void {
      // some code
      ..........
   }

我在这里做错了什么?你能救我吗?

1 个答案:

答案 0 :(得分:1)

Shape对象是非交互式的,因此它们不会触发鼠标事件等。

使用另一个继承自InteractiveObject的对象,而不是使用Shape。 精灵可能是个不错的选择。

但是,如果我正在使用图形对象,我总是将我的对象声明为MovieClip。

shape:Sprite = new Sprite();

shape:MovieClip = new MovieClip();

在这里查看Shape的继承事件; http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Shape.html

...并在此处与Sprite的继承事件进行比较; http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Sprite.html