我正在尝试向我的BitMap添加一个事件监听器。 Tile扩展了gameProps,扩展了BitMap。我尝试使用addEventListener。那不起作用。但是Adobe文档说Bitmap有一个addEventListener对象。
package {
import flash.display.BitmapData;
import flash.events.*;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.geom.Point;
public class Tile extends gameProps {
public var tileNum:Number = 0;
public function Tile(tileNumber:Number):void
{
tileNum = tileNumber;
addEventListener(MouseEvent.MOUSE_OVER, respond);
}
public function respond(e:MouseEvent):void
{ trace("HELLO");
}
}
}
答案 0 :(得分:5)
Bitmap类扩展了DisplayObject而不是InteractiveObject,因此无法接收鼠标事件。尝试将位图对象包装在Sprite子类中。像这样的东西(伪代码):
public class Image extends Sprite
{
var bitmap:Bitmap;
public function Image()
{
bitmap = new Bitmap();
addChild( bitmap );
}
}
InteractiveObject文档:http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/InteractiveObject.html