开发者

BitMap Eventlistener not working

I am trying to add an event listener to my BitMap. Tile extends gameProps, which extends BitMap. I try using addEventListener. That doesnt work. but the Adobe docs say that Bitmap has an addEventListener object.

 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 {

       开发者_StackOverflow社区         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");             
                }

            }   
        }


The Bitmap class extends the DisplayObject not the InteractiveObject and can therefore not receive mouse events. Try wrapping the bitmap object in a Sprite sub-class. Something like this (pseudo-code):

public class Image extends Sprite
{
     var bitmap:Bitmap;

     public function Image()
     {
         bitmap = new Bitmap();
         addChild( bitmap );
     }
}

InteractiveObject Docs: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/InteractiveObject.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜